diff --git a/data.cpp b/data.cpp
index 65f706e..c028897 100644
--- a/data.cpp
+++ b/data.cpp
@@ -43,26 +43,26 @@
 #include "gui/blanktimer.hpp"
 
 #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
-    #include "cutils/properties.h"
+	#include "cutils/properties.h"
 #endif
 
 extern "C"
 {
-    #include "twcommon.h"
-    #include "data.h"
+	#include "twcommon.h"
+	#include "data.h"
 	#include "gui/pages.h"
 
 	void gui_notifyVarChange(const char *name, const char* value);
 }
 
-#define FILE_VERSION    0x00010001
+#define FILE_VERSION 0x00010001
 
 using namespace std;
 
-map<string, DataManager::TStrIntPair>   DataManager::mValues;
-map<string, string>                     DataManager::mConstValues;
-string                                  DataManager::mBackingFile;
-int                                     DataManager::mInitialized = 0;
+map<string, DataManager::TStrIntPair>	DataManager::mValues;
+map<string, string>					 	DataManager::mConstValues;
+string									DataManager::mBackingFile;
+int										DataManager::mInitialized = 0;
 extern blanktimer blankTimer;
 
 // Device ID functions
@@ -81,12 +81,12 @@
 	return;
 }
 
-#define CMDLINE_SERIALNO        "androidboot.serialno="
-#define CMDLINE_SERIALNO_LEN    (strlen(CMDLINE_SERIALNO))
-#define CPUINFO_SERIALNO        "Serial"
-#define CPUINFO_SERIALNO_LEN    (strlen(CPUINFO_SERIALNO))
-#define CPUINFO_HARDWARE        "Hardware"
-#define CPUINFO_HARDWARE_LEN    (strlen(CPUINFO_HARDWARE))
+#define CMDLINE_SERIALNO		"androidboot.serialno="
+#define CMDLINE_SERIALNO_LEN	(strlen(CMDLINE_SERIALNO))
+#define CPUINFO_SERIALNO		"Serial"
+#define CPUINFO_SERIALNO_LEN	(strlen(CPUINFO_SERIALNO))
+#define CPUINFO_HARDWARE		"Hardware"
+#define CPUINFO_HARDWARE_LEN	(strlen(CPUINFO_HARDWARE))
 
 void DataManager::get_device_id(void) {
 	FILE *fp;
@@ -94,8 +94,8 @@
 	char hardware_id[32], device_id[64];
 	char* token;
 
-    // Assign a blank device_id to start with
-    device_id[0] = 0;
+	// Assign a blank device_id to start with
+	device_id[0] = 0;
 
 #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
 	// Now we'll use product_model_hardwareid as device id
@@ -121,37 +121,37 @@
 #endif
 
 #ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID
-    // First, try the cmdline to see if the serial number was supplied
+	// First, try the cmdline to see if the serial number was supplied
 	fp = fopen("/proc/cmdline", "rt");
 	if (fp != NULL)
-    {
-        // First step, read the line. For cmdline, it's one long line
-        fgets(line, sizeof(line), fp);
-        fclose(fp);
+	{
+		// First step, read the line. For cmdline, it's one long line
+		fgets(line, sizeof(line), fp);
+		fclose(fp);
 
-        // Now, let's tokenize the string
-        token = strtok(line, " ");
+		// Now, let's tokenize the string
+		token = strtok(line, " ");
 
-        // Let's walk through the line, looking for the CMDLINE_SERIALNO token
-        while (token)
-        {
-            // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
-            if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
-            {
-                // We found the serial number!
-                strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
+		// Let's walk through the line, looking for the CMDLINE_SERIALNO token
+		while (token)
+		{
+			// We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
+			if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
+			{
+				// We found the serial number!
+				strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
 				sanitize_device_id((char *)device_id);
 				mConstValues.insert(make_pair("device_id", device_id));
-                return;
-            }
-            token = strtok(NULL, " ");
-        }
-    }
+				return;
+			}
+			token = strtok(NULL, " ");
+		}
+	}
 #endif
 	// Now we'll try cpuinfo for a serial number
 	fp = fopen("/proc/cpuinfo", "rt");
 	if (fp != NULL)
-    {
+	{
 		while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line.
 			if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0)  // check the beginning of the line for "Serial"
 			{
@@ -159,7 +159,7 @@
 				token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial"
 				while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
 				if (*token != 0) {
-                    token[30] = 0;
+					token[30] = 0;
 					if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
 						memset(device_id, 0, sizeof(device_id));
 						strncpy(device_id, token, strlen(token) - 1);
@@ -177,9 +177,9 @@
 				token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware"
 				while ((*token > 0 && *token <= 32 ) || *token == ':')  token++; // skip over all spaces and the colon
 				if (*token != 0) {
-                    token[30] = 0;
+					token[30] = 0;
 					if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
-                        memset(hardware_id, 0, sizeof(hardware_id));
+						memset(hardware_id, 0, sizeof(hardware_id));
 						strncpy(hardware_id, token, strlen(token) - 1);
 					} else {
 						strcpy(hardware_id, token);
@@ -189,7 +189,7 @@
 			}
 		}
 		fclose(fp);
-    }
+	}
 
 	if (hardware_id[0] != 0) {
 		LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id);
@@ -199,76 +199,76 @@
 		return;
 	}
 
-    strcpy(device_id, "serialno");
+	strcpy(device_id, "serialno");
 	LOGERR("=> device id not found, using '%s'.", device_id);
 	mConstValues.insert(make_pair("device_id", device_id));
-    return;
+	return;
 }
 
 int DataManager::ResetDefaults()
 {
-    mValues.clear();
-    mConstValues.clear();
-    SetDefaultValues();
-    return 0;
+	mValues.clear();
+	mConstValues.clear();
+	SetDefaultValues();
+	return 0;
 }
 
 int DataManager::LoadValues(const string filename)
 {
-    string str, dev_id;
+	string str, dev_id;
 
 	if (!mInitialized)
-        SetDefaultValues();
+		SetDefaultValues();
 
-    GetValue("device_id", dev_id);
+	GetValue("device_id", dev_id);
 	// Save off the backing file for set operations
-    mBackingFile = filename;
+	mBackingFile = filename;
 
-    // Read in the file, if possible
-    FILE* in = fopen(filename.c_str(), "rb");
-    if (!in) {
+	// Read in the file, if possible
+	FILE* in = fopen(filename.c_str(), "rb");
+	if (!in) {
 		LOGINFO("Settings file '%s' not found.\n", filename.c_str());
 		return 0;
 	} else {
 		LOGINFO("Loading settings from '%s'.\n", filename.c_str());
 	}
 
-    int file_version;
-    if (fread(&file_version, 1, sizeof(int), in) != sizeof(int))    goto error;
-    if (file_version != FILE_VERSION)                               goto error;
+	int file_version;
+	if (fread(&file_version, 1, sizeof(int), in) != sizeof(int))	goto error;
+	if (file_version != FILE_VERSION)								goto error;
 
-    while (!feof(in))
-    {
-        string Name;
-        string Value;
-        unsigned short length;
-        char array[512];
+	while (!feof(in))
+	{
+		string Name;
+		string Value;
+		unsigned short length;
+		char array[512];
 
-        if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short))    goto error;
-        if (length >= 512)                                                              goto error;
-        if (fread(array, 1, length, in) != length)                                      goto error;
-        Name = array;
+		if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short))	goto error;
+		if (length >= 512)																goto error;
+		if (fread(array, 1, length, in) != length)										goto error;
+		Name = array;
 
-        if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short))    goto error;
-        if (length >= 512)                                                              goto error;
-        if (fread(array, 1, length, in) != length)                                      goto error;
-        Value = array;
+		if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short))	goto error;
+		if (length >= 512)																goto error;
+		if (fread(array, 1, length, in) != length)										goto error;
+		Value = array;
 
-        map<string, TStrIntPair>::iterator pos;
+		map<string, TStrIntPair>::iterator pos;
 
-        pos = mValues.find(Name);
-        if (pos != mValues.end())
-        {
-            pos->second.first = Value;
-            pos->second.second = 1;
-        }
-        else
-            mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
+		pos = mValues.find(Name);
+		if (pos != mValues.end())
+		{
+			pos->second.first = Value;
+			pos->second.second = 1;
+		}
+		else
+			mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
 		if (Name == "tw_screen_timeout_secs")
 			blankTimer.setTime(atoi(Value.c_str()));
-    }
+	}
 error:
-    fclose(in);
+	fclose(in);
 	string current = GetCurrentStoragePath();
 	string settings = GetSettingsStoragePath();
 	if (current != settings && !PartitionManager.Mount_By_Path(current, false)) {
@@ -276,185 +276,188 @@
 	} else {
 		SetBackupFolder();
 	}
-    return 0;
+	return 0;
 }
 
 int DataManager::Flush()
 {
-    return SaveValues();
+	return SaveValues();
 }
 
 int DataManager::SaveValues()
 {
-    if (mBackingFile.empty())       return -1;
+	if (mBackingFile.empty())
+		return -1;
 
 	string mount_path = GetSettingsStoragePath();
 	PartitionManager.Mount_By_Path(mount_path.c_str(), 1);
 
 	FILE* out = fopen(mBackingFile.c_str(), "wb");
-    if (!out)                       return -1;
+	if (!out)
+		return -1;
 
-    int file_version = FILE_VERSION;
-    fwrite(&file_version, 1, sizeof(int), out);
+	int file_version = FILE_VERSION;
+	fwrite(&file_version, 1, sizeof(int), out);
 
-    map<string, TStrIntPair>::iterator iter;
-    for (iter = mValues.begin(); iter != mValues.end(); ++iter)
-    {
-        // Save only the persisted data
-        if (iter->second.second != 0)
-        {
-            unsigned short length = (unsigned short) iter->first.length() + 1;
-            fwrite(&length, 1, sizeof(unsigned short), out);
-            fwrite(iter->first.c_str(), 1, length, out);
-            length = (unsigned short) iter->second.first.length() + 1;
-            fwrite(&length, 1, sizeof(unsigned short), out);
-            fwrite(iter->second.first.c_str(), 1, length, out);
-        }
-    }
-    fclose(out);
-    return 0;
+	map<string, TStrIntPair>::iterator iter;
+	for (iter = mValues.begin(); iter != mValues.end(); ++iter)
+	{
+		// Save only the persisted data
+		if (iter->second.second != 0)
+		{
+			unsigned short length = (unsigned short) iter->first.length() + 1;
+			fwrite(&length, 1, sizeof(unsigned short), out);
+			fwrite(iter->first.c_str(), 1, length, out);
+			length = (unsigned short) iter->second.first.length() + 1;
+			fwrite(&length, 1, sizeof(unsigned short), out);
+			fwrite(iter->second.first.c_str(), 1, length, out);
+		}
+	}
+	fclose(out);
+	return 0;
 }
 
 int DataManager::GetValue(const string varName, string& value)
 {
-    string localStr = varName;
+	string localStr = varName;
 
-    if (!mInitialized)
-        SetDefaultValues();
+	if (!mInitialized)
+		SetDefaultValues();
 
-    // Strip off leading and trailing '%' if provided
-    if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
-    {
-        localStr.erase(0, 1);
-        localStr.erase(localStr.length() - 1, 1);
-    }
+	// Strip off leading and trailing '%' if provided
+	if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
+	{
+		localStr.erase(0, 1);
+		localStr.erase(localStr.length() - 1, 1);
+	}
 
-    // Handle magic values
-    if (GetMagicValue(localStr, value) == 0)     return 0;
+	// Handle magic values
+	if (GetMagicValue(localStr, value) == 0)
+		return 0;
 
-    map<string, string>::iterator constPos;
-    constPos = mConstValues.find(localStr);
-    if (constPos != mConstValues.end())
-    {
-        value = constPos->second;
-        return 0;
-    }
+	map<string, string>::iterator constPos;
+	constPos = mConstValues.find(localStr);
+	if (constPos != mConstValues.end())
+	{
+		value = constPos->second;
+		return 0;
+	}
 
-    map<string, TStrIntPair>::iterator pos;
-    pos = mValues.find(localStr);
-    if (pos == mValues.end())
-        return -1;
+	map<string, TStrIntPair>::iterator pos;
+	pos = mValues.find(localStr);
+	if (pos == mValues.end())
+		return -1;
 
-    value = pos->second.first;
-    return 0;
+	value = pos->second.first;
+	return 0;
 }
 
 int DataManager::GetValue(const string varName, int& value)
 {
-    string data;
+	string data;
 
-    if (GetValue(varName,data) != 0)
-        return -1;
+	if (GetValue(varName,data) != 0)
+		return -1;
 
-    value = atoi(data.c_str());
-    return 0;
+	value = atoi(data.c_str());
+	return 0;
 }
 
 int DataManager::GetValue(const string varName, float& value)
 {
-    string data;
+	string data;
 
-    if (GetValue(varName,data) != 0)
-        return -1;
+	if (GetValue(varName,data) != 0)
+		return -1;
 
-    value = atof(data.c_str());
-    return 0;
+	value = atof(data.c_str());
+	return 0;
 }
 
 unsigned long long DataManager::GetValue(const string varName, unsigned long long& value)
 {
-    string data;
+	string data;
 
-    if (GetValue(varName,data) != 0)
-        return -1;
+	if (GetValue(varName,data) != 0)
+		return -1;
 
-    value = strtoull(data.c_str(), NULL, 10);
-    return 0;
+	value = strtoull(data.c_str(), NULL, 10);
+	return 0;
 }
 
 // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
 string& DataManager::GetValueRef(const string varName)
 {
-    if (!mInitialized)
-        SetDefaultValues();
+	if (!mInitialized)
+		SetDefaultValues();
 
-    map<string, string>::iterator constPos;
-    constPos = mConstValues.find(varName);
-    if (constPos != mConstValues.end())
-        return constPos->second;
+	map<string, string>::iterator constPos;
+	constPos = mConstValues.find(varName);
+	if (constPos != mConstValues.end())
+		return constPos->second;
 
-    map<string, TStrIntPair>::iterator pos;
-    pos = mValues.find(varName);
-    if (pos == mValues.end())
-        pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
+	map<string, TStrIntPair>::iterator pos;
+	pos = mValues.find(varName);
+	if (pos == mValues.end())
+		pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
 
-    return pos->second.first;
+	return pos->second.first;
 }
 
 // This function will return an empty string if the value doesn't exist
 string DataManager::GetStrValue(const string varName)
 {
-    string retVal;
+	string retVal;
 
-    GetValue(varName, retVal);
-    return retVal;
+	GetValue(varName, retVal);
+	return retVal;
 }
 
 // This function will return 0 if the value doesn't exist
 int DataManager::GetIntValue(const string varName)
 {
-    string retVal;
+	string retVal;
 
-    GetValue(varName, retVal);
-    return atoi(retVal.c_str());
+	GetValue(varName, retVal);
+	return atoi(retVal.c_str());
 }
 
 int DataManager::SetValue(const string varName, string value, int persist /* = 0 */)
 {
-    if (!mInitialized)
-        SetDefaultValues();
+	if (!mInitialized)
+		SetDefaultValues();
 
-    // Don't allow empty values or numerical starting values
-    if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
-        return -1;
+	// Don't allow empty values or numerical starting values
+	if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
+		return -1;
 
-    map<string, string>::iterator constChk;
-    constChk = mConstValues.find(varName);
-    if (constChk != mConstValues.end())
-        return -1;
+	map<string, string>::iterator constChk;
+	constChk = mConstValues.find(varName);
+	if (constChk != mConstValues.end())
+		return -1;
 
-    map<string, TStrIntPair>::iterator pos;
-    pos = mValues.find(varName);
-    if (pos == mValues.end())
-        pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
-    else
-        pos->second.first = value;
+	map<string, TStrIntPair>::iterator pos;
+	pos = mValues.find(varName);
+	if (pos == mValues.end())
+		pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
+	else
+		pos->second.first = value;
 
-    if (pos->second.second != 0)
-        SaveValues();
+	if (pos->second.second != 0)
+		SaveValues();
 	if (varName == "tw_screen_timeout_secs") {
 		blankTimer.setTime(atoi(value.c_str()));
 	} else if (varName == "tw_storage_path") {
 		SetBackupFolder();
 	}
 	gui_notifyVarChange(varName.c_str(), value.c_str());
-    return 0;
+	return 0;
 }
 
 int DataManager::SetValue(const string varName, int value, int persist /* = 0 */)
 {
 	ostringstream valStr;
-    valStr << value;
+	valStr << value;
 	if (varName == "tw_use_external_storage") {
 		string str;
 
@@ -471,28 +474,29 @@
 
 		SetValue("tw_storage_path", str);
 	}
-    return SetValue(varName, valStr.str(), persist);
+	return SetValue(varName, valStr.str(), persist);
 }
 
 int DataManager::SetValue(const string varName, float value, int persist /* = 0 */)
 {
 	ostringstream valStr;
-    valStr << value;
-    return SetValue(varName, valStr.str(), persist);;
+	valStr << value;
+	return SetValue(varName, valStr.str(), persist);;
 }
 
 int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */)
 {
 	ostringstream valStr;
-    valStr << value;
-    return SetValue(varName, valStr.str(), persist);;
+	valStr << value;
+	return SetValue(varName, valStr.str(), persist);
 }
 
 int DataManager::SetProgress(float Fraction) {
 	return SetValue("ui_progress", (float) (Fraction * 100.0));
 }
 
-int DataManager::ShowProgress(float Portion, float Seconds) {
+int DataManager::ShowProgress(float Portion, float Seconds)
+{
 	float Starting_Portion;
 	GetValue("ui_progress_portion", Starting_Portion);
 	if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0)
@@ -504,17 +508,16 @@
 
 void DataManager::DumpValues()
 {
-    map<string, TStrIntPair>::iterator iter;
-    gui_print("Data Manager dump - Values with leading X are persisted.\n");
-    for (iter = mValues.begin(); iter != mValues.end(); ++iter)
-    {
-        gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
-    }
+	map<string, TStrIntPair>::iterator iter;
+	gui_print("Data Manager dump - Values with leading X are persisted.\n");
+	for (iter = mValues.begin(); iter != mValues.end(); ++iter)
+		gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
 }
 
-void DataManager::update_tz_environment_variables(void) {
+void DataManager::update_tz_environment_variables(void)
+{
 	setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1);
-    tzset();
+	tzset();
 }
 
 void DataManager::SetBackupFolder()
@@ -526,7 +529,7 @@
 	string dev_id;
 	GetValue("device_id", dev_id);
 
-    str += dev_id;
+	str += dev_id;
 	LOGINFO("Backup folder set to '%s'\n", str.c_str());
 	SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
 	if (partition != NULL) {
@@ -558,16 +561,16 @@
 
 void DataManager::SetDefaultValues()
 {
-    string str, path;
+	string str, path;
 
-    get_device_id();
+	get_device_id();
 
-    mInitialized = 1;
+	mInitialized = 1;
 
-    mConstValues.insert(make_pair("true", "1"));
-    mConstValues.insert(make_pair("false", "0"));
+	mConstValues.insert(make_pair("true", "1"));
+	mConstValues.insert(make_pair("false", "0"));
 
-    mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
+	mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
 	mValues.insert(make_pair("tw_storage_path", make_pair("/", 1)));
 
 #ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID
@@ -576,9 +579,9 @@
 
 #ifdef BOARD_HAS_NO_REAL_SDCARD
 	printf("BOARD_HAS_NO_REAL_SDCARD := true\n");
-    mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
+	mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
 #else
-    mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
+	mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
 #endif
 
 #ifdef TW_INCLUDE_DUMLOCK
@@ -720,45 +723,45 @@
 	string dev_id;
 	GetValue("device_id", dev_id);
 
-    str += dev_id;
+	str += dev_id;
 	SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
 
 #ifdef SP1_DISPLAY_NAME
 	printf("SP1_DISPLAY_NAME := %s\n", EXPAND(SP1_DISPLAY_NAME));
-    if (strlen(EXPAND(SP1_DISPLAY_NAME)))    mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME)));
+	if (strlen(EXPAND(SP1_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME)));
 #else
 	#ifdef SP1_NAME
 		printf("SP1_NAME := %s\n", EXPAND(SP1_NAME));
-		if (strlen(EXPAND(SP1_NAME)))    mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME)));
+		if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME)));
 	#endif
 #endif
 #ifdef SP2_DISPLAY_NAME
 	printf("SP2_DISPLAY_NAME := %s\n", EXPAND(SP2_DISPLAY_NAME));
-    if (strlen(EXPAND(SP2_DISPLAY_NAME)))    mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME)));
+	if (strlen(EXPAND(SP2_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME)));
 #else
 	#ifdef SP2_NAME
 		printf("SP2_NAME := %s\n", EXPAND(SP2_NAME));
-		if (strlen(EXPAND(SP2_NAME)))    mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_NAME)));
+		if (strlen(EXPAND(SP2_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_NAME)));
 	#endif
 #endif
 #ifdef SP3_DISPLAY_NAME
 	printf("SP3_DISPLAY_NAME := %s\n", EXPAND(SP3_DISPLAY_NAME));
-    if (strlen(EXPAND(SP3_DISPLAY_NAME)))    mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME)));
+	if (strlen(EXPAND(SP3_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME)));
 #else
 	#ifdef SP3_NAME
 		printf("SP3_NAME := %s\n", EXPAND(SP3_NAME));
-		if (strlen(EXPAND(SP3_NAME)))    mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_NAME)));
+		if (strlen(EXPAND(SP3_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_NAME)));
 	#endif
 #endif
 
-    mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1"));
+	mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1"));
 #ifdef TW_NO_REBOOT_RECOVERY
 	printf("TW_NO_REBOOT_RECOVERY := true\n");
 	mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0"));
 #else
 	mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1"));
 #endif
-    mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1"));
+	mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1"));
 #ifdef TW_NO_REBOOT_BOOTLOADER
 	printf("TW_NO_REBOOT_BOOTLOADER := true\n");
 	mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0"));
@@ -843,15 +846,15 @@
 	mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
 	mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0)));
 	mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1)));
-    mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
-    mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1)));
-    mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
+	mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1)));
+	mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1)));
 	mValues.insert(make_pair(TW_BACKUP_SYSTEM_SIZE, make_pair("0", 0)));
 	mValues.insert(make_pair(TW_BACKUP_DATA_SIZE, make_pair("0", 0)));
 	mValues.insert(make_pair(TW_BACKUP_BOOT_SIZE, make_pair("0", 0)));
@@ -864,33 +867,33 @@
 	mValues.insert(make_pair(TW_BACKUP_SP3_SIZE, make_pair("0", 0)));
 	mValues.insert(make_pair(TW_STORAGE_FREE_SIZE, make_pair("0", 0)));
 
-    mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
-    mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
-    mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
-    mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
-    mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
-    mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
-    mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
-    mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
-    mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
-    mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1)));
-    mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1)));
-    mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
-    mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1)));
-    mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1)));
-    mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
-    mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0)));
-    mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0)));
+	mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
+	mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
+	mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
+	mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
+	mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
+	mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
+	mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
+	mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
+	mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
+	mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1)));
+	mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1)));
+	mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
+	mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1)));
+	mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1)));
+	mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
+	mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0)));
+	mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0)));
 	if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0)
 		SetValue(TW_HAS_USB_STORAGE, 0, 0);
 	else
@@ -940,35 +943,37 @@
 // Magic Values
 int DataManager::GetMagicValue(const string varName, string& value)
 {
-    // Handle special dynamic cases
-    if (varName == "tw_time")
-    {
-        char tmp[32];
+	// Handle special dynamic cases
+	if (varName == "tw_time")
+	{
+		char tmp[32];
 
-        struct tm *current;
-        time_t now;
-	int tw_military_time;
-        now = time(0);
-        current = localtime(&now);
-	GetValue(TW_MILITARY_TIME, tw_military_time); 
-        if (current->tm_hour >= 12) {
-		if (tw_military_time == 1)
-            		sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
-		else
-            		sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
+		struct tm *current;
+		time_t now;
+		int tw_military_time;
+		now = time(0);
+		current = localtime(&now);
+		GetValue(TW_MILITARY_TIME, tw_military_time); 
+		if (current->tm_hour >= 12)
+		{
+			if (tw_military_time == 1)
+				sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
+			else
+				sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
 		}
-        else {
-		if (tw_military_time == 1) 
-		    sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
 		else
-		    sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
+		{
+			if (tw_military_time == 1) 
+				sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
+			else
+				sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
+		}
+		value = tmp;
+		return 0;
 	}
-        value = tmp;
-        return 0;
-    }
-    if (varName == "tw_battery")
-    {
-        char tmp[16];
+	else if (varName == "tw_battery")
+	{
+		char tmp[16];
 		static char charging = ' ';
 		static int lastVal = -1;
 		static time_t nextSecCheck = 0;
@@ -989,8 +994,8 @@
 				fgets(cap_s, 4, cap);
 				fclose(cap);
 				lastVal = atoi(cap_s);
-				if (lastVal > 100)  lastVal = 101;
-				if (lastVal < 0)    lastVal = 0;
+				if (lastVal > 100)	lastVal = 101;
+				if (lastVal < 0)	lastVal = 0;
 			}
 #ifdef TW_CUSTOM_BATTERY_PATH
 			string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
@@ -1011,13 +1016,14 @@
 		}
 
 		sprintf(tmp, "%i%%%c", lastVal, charging);
-        value = tmp;
-        return 0;
-    }
-    return -1;
+		value = tmp;
+		return 0;
+	}
+	return -1;
 }
 
-void DataManager::Output_Version(void) {
+void DataManager::Output_Version(void)
+{
 	string Path;
 	char version[255];
 
@@ -1131,89 +1137,89 @@
 	return GetValueRef("tw_settings_path");
 }
 
-extern "C" int DataManager_ResetDefaults()
+extern "C" int DataManager_ResetDefaults(void)
 {
-    return DataManager::ResetDefaults();
+	return DataManager::ResetDefaults();
 }
 
-extern "C" void DataManager_LoadDefaults()
+extern "C" void DataManager_LoadDefaults(void)
 {
-    return DataManager::SetDefaultValues();
+	return DataManager::SetDefaultValues();
 }
 
 extern "C" int DataManager_LoadValues(const char* filename)
 {
-    return DataManager::LoadValues(filename);
+	return DataManager::LoadValues(filename);
 }
 
-extern "C" int DataManager_Flush()
+extern "C" int DataManager_Flush(void)
 {
-    return DataManager::Flush();
+	return DataManager::Flush();
 }
 
 extern "C" int DataManager_GetValue(const char* varName, char* value)
 {
-    int ret;
-    string str;
+	int ret;
+	string str;
 
-    ret = DataManager::GetValue(varName, str);
-    if (ret == 0)
-        strcpy(value, str.c_str());
-    return ret;
+	ret = DataManager::GetValue(varName, str);
+	if (ret == 0)
+		strcpy(value, str.c_str());
+	return ret;
 }
 
 extern "C" const char* DataManager_GetStrValue(const char* varName)
 {
-    string& str = DataManager::GetValueRef(varName);
-    return str.c_str();
+	string& str = DataManager::GetValueRef(varName);
+	return str.c_str();
 }
 
 extern "C" const char* DataManager_GetCurrentStoragePath(void)
 {
-    string& str = DataManager::CGetCurrentStoragePath();
-    return str.c_str();
+	string& str = DataManager::CGetCurrentStoragePath();
+	return str.c_str();
 }
 
 extern "C" const char* DataManager_GetSettingsStoragePath(void)
 {
-    string& str = DataManager::CGetSettingsStoragePath();
-    return str.c_str();
+	string& str = DataManager::CGetSettingsStoragePath();
+	return str.c_str();
 }
 
 extern "C" int DataManager_GetIntValue(const char* varName)
 {
-    return DataManager::GetIntValue(varName);
+	return DataManager::GetIntValue(varName);
 }
 
 extern "C" int DataManager_SetStrValue(const char* varName, char* value)
 {
-    return DataManager::SetValue(varName, value, 0);
+	return DataManager::SetValue(varName, value, 0);
 }
 
 extern "C" int DataManager_SetIntValue(const char* varName, int value)
 {
-    return DataManager::SetValue(varName, value, 0);
+	return DataManager::SetValue(varName, value, 0);
 }
 
 extern "C" int DataManager_SetFloatValue(const char* varName, float value)
 {
-    return DataManager::SetValue(varName, value, 0);
+	return DataManager::SetValue(varName, value, 0);
 }
 
 extern "C" int DataManager_ToggleIntValue(const char* varName)
 {
-    if (DataManager::GetIntValue(varName))
-        return DataManager::SetValue(varName, 0);
-    else
-        return DataManager::SetValue(varName, 1);
+	if (DataManager::GetIntValue(varName))
+		return DataManager::SetValue(varName, 0);
+	else
+		return DataManager::SetValue(varName, 1);
 }
 
-extern "C" void DataManager_DumpValues()
+extern "C" void DataManager_DumpValues(void)
 {
-    return DataManager::DumpValues();
+	return DataManager::DumpValues();
 }
 
-extern "C" void DataManager_ReadSettingsFile()
+extern "C" void DataManager_ReadSettingsFile(void)
 {
-    return DataManager::ReadSettingsFile();
+	return DataManager::ReadSettingsFile();
 }
diff --git a/data.h b/data.h
index 3137f8f..f9639c6 100644
--- a/data.h
+++ b/data.h
@@ -17,13 +17,13 @@
 #ifndef _DATA_HEADER
 #define _DATA_HEADER
 
-int DataManager_ResetDefaults();
-void DataManager_LoadDefaults();
+int DataManager_ResetDefaults(void);
+void DataManager_LoadDefaults(void);
 int DataManager_LoadValues(const char* filename);
-int DataManager_Flush();
+int DataManager_Flush(void);
 const char* DataManager_GetStrValue(const char* varName);
-const char* DataManager_GetCurrentStoragePath();
-const char* DataManager_GetSettingsStoragePath();
+const char* DataManager_GetCurrentStoragePath(void);
+const char* DataManager_GetSettingsStoragePath(void);
 int DataManager_GetIntValue(const char* varName);
 
 int DataManager_SetStrValue(const char* varName, char* value);
@@ -32,8 +32,8 @@
 
 int DataManager_ToggleIntValue(const char* varName);
 
-void DataManager_DumpValues();
-void DataManager_ReadSettingsFile();
+void DataManager_DumpValues(void);
+void DataManager_ReadSettingsFile(void);
 
 #endif  // _DATA_HEADER
 
diff --git a/data.hpp b/data.hpp
index ff50373..ef201d7 100644
--- a/data.hpp
+++ b/data.hpp
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,32 +26,32 @@
 class DataManager
 {
 public:
-    static int ResetDefaults();
-    static int LoadValues(const string filename);
-    static int Flush();
+	static int ResetDefaults();
+	static int LoadValues(const string filename);
+	static int Flush();
 
-    // Core get routines
-    static int GetValue(const string varName, string& value);
-    static int GetValue(const string varName, int& value);
+	// Core get routines
+	static int GetValue(const string varName, string& value);
+	static int GetValue(const string varName, int& value);
 	static int GetValue(const string varName, float& value);
-    static unsigned long long GetValue(const string varName, unsigned long long& value);
+	static unsigned long long GetValue(const string varName, unsigned long long& value);
 
-    // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
-    static string& GetValueRef(const string varName);
+	// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
+	static string& GetValueRef(const string varName);
 
-    // Helper functions
-    static string GetStrValue(const string varName);
-    static int GetIntValue(const string varName);
+	// Helper functions
+	static string GetStrValue(const string varName);
+	static int GetIntValue(const string varName);
 
-    // Core set routines
-    static int SetValue(const string varName, string value, int persist = 0);
-    static int SetValue(const string varName, int value, int persist = 0);
-    static int SetValue(const string varName, float value, int persist = 0);
-    static int SetValue(const string varName, unsigned long long value, int persist = 0);
+	// Core set routines
+	static int SetValue(const string varName, string value, int persist = 0);
+	static int SetValue(const string varName, int value, int persist = 0);
+	static int SetValue(const string varName, float value, int persist = 0);
+	static int SetValue(const string varName, unsigned long long value, int persist = 0);
 	static int SetProgress(float Fraction);
 	static int ShowProgress(float Portion, float Seconds);
 
-    static void DumpValues();
+	static void DumpValues();
 	static void update_tz_environment_variables();
 	static void SetBackupFolder();
 	static void SetDefaultValues();
@@ -64,20 +64,20 @@
 	static string& CGetSettingsStoragePath();
 
 protected:
-    typedef pair<string, int> TStrIntPair;
-    typedef pair<string, unsigned long long> TStrULLPair;
-    typedef pair<string, TStrIntPair> TNameValuePair;
-    static map<string, TStrIntPair> mValues;
-    static map<string, TStrULLPair> mULLValues;
-    static string mBackingFile;
-    static int mInitialized;
+	typedef pair<string, int> TStrIntPair;
+	typedef pair<string, unsigned long long> TStrULLPair;
+	typedef pair<string, TStrIntPair> TNameValuePair;
+	static map<string, TStrIntPair> mValues;
+	static map<string, TStrULLPair> mULLValues;
+	static string mBackingFile;
+	static int mInitialized;
 
-    static map<string, string> mConstValues;
+	static map<string, string> mConstValues;
 
 protected:
-    static int SaveValues();
+	static int SaveValues();
 
-    static int GetMagicValue(string varName, string& value);
+	static int GetMagicValue(string varName, string& value);
 
 private:
 	static void sanitize_device_id(char* device_id);
diff --git a/gui/action.cpp b/gui/action.cpp
index 3e1f793..ee33731 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -64,72 +64,72 @@
 void curtainClose(void);
 
 GUIAction::GUIAction(xml_node<>* node)
-    : Conditional(node)
+	: Conditional(node)
 {
-    xml_node<>* child;
-    xml_node<>* actions;
-    xml_attribute<>* attr;
+	xml_node<>* child;
+	xml_node<>* actions;
+	xml_attribute<>* attr;
 
-    mKey = 0;
+	mKey = 0;
 
-    if (!node)  return;
+	if (!node)  return;
 
-    // First, get the action
-    actions = node->first_node("actions");
-    if (actions)    child = actions->first_node("action");
-    else            child = node->first_node("action");
+	// First, get the action
+	actions = node->first_node("actions");
+	if (actions)	child = actions->first_node("action");
+	else			child = node->first_node("action");
 
-    if (!child) return;
+	if (!child) return;
 
-    while (child)
-    {
-        Action action;
+	while (child)
+	{
+		Action action;
 
-        attr = child->first_attribute("function");
-        if (!attr)  return;
-    
-        action.mFunction = attr->value();
-        action.mArg = child->value();
-        mActions.push_back(action);
+		attr = child->first_attribute("function");
+		if (!attr)  return;
+	
+		action.mFunction = attr->value();
+		action.mArg = child->value();
+		mActions.push_back(action);
 
-        child = child->next_sibling("action");
-    }
+		child = child->next_sibling("action");
+	}
 
-    // Now, let's get either the key or region
-    child = node->first_node("touch");
-    if (child)
-    {
-        attr = child->first_attribute("key");
-        if (attr)
-        {
-            std::string key = attr->value();
-    
-            mKey = getKeyByName(key);
-        }
-        else
-        {
-            attr = child->first_attribute("x");
-            if (!attr)  return;
-            mActionX = atol(attr->value());
-            attr = child->first_attribute("y");
-            if (!attr)  return;
-            mActionY = atol(attr->value());
-            attr = child->first_attribute("w");
-            if (!attr)  return;
-            mActionW = atol(attr->value());
-            attr = child->first_attribute("h");
-            if (!attr)  return;
-            mActionH = atol(attr->value());
-        }
-    }
+	// Now, let's get either the key or region
+	child = node->first_node("touch");
+	if (child)
+	{
+		attr = child->first_attribute("key");
+		if (attr)
+		{
+			std::string key = attr->value();
+	
+			mKey = getKeyByName(key);
+		}
+		else
+		{
+			attr = child->first_attribute("x");
+			if (!attr)  return;
+			mActionX = atol(attr->value());
+			attr = child->first_attribute("y");
+			if (!attr)  return;
+			mActionY = atol(attr->value());
+			attr = child->first_attribute("w");
+			if (!attr)  return;
+			mActionW = atol(attr->value());
+			attr = child->first_attribute("h");
+			if (!attr)  return;
+			mActionH = atol(attr->value());
+		}
+	}
 }
 
 int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    if (state == TOUCH_RELEASE)
-        doActions();
+	if (state == TOUCH_RELEASE)
+		doActions();
 
-    return 0;
+	return 0;
 }
 
 int GUIAction::NotifyKey(int key)
@@ -143,17 +143,17 @@
 
 int GUIAction::NotifyVarChange(std::string varName, std::string value)
 {
-    if (varName.empty() && !isConditionValid() && !mKey && !mActionW)
-        doActions();
+	if (varName.empty() && !isConditionValid() && !mKey && !mActionW)
+		doActions();
 
-    // This handles notifying the condition system of page start
-    if (varName.empty() && isConditionValid())
-        NotifyPageSet();
+	// This handles notifying the condition system of page start
+	if (varName.empty() && isConditionValid())
+		NotifyPageSet();
 
-    if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
-        doActions();
+	if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
+		doActions();
 
-    return 0;
+	return 0;
 }
 
 void GUIAction::simulate_progress_bar(void)
@@ -168,54 +168,54 @@
 
 int GUIAction::flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache)
 {
-    int ret_val = 0;
+	int ret_val = 0;
 
 	DataManager::SetValue("ui_progress", 0);
 
-    if (filename.empty())
-    {
-        LOGERR("No file specified.\n");
-        return -1;
-    }
+	if (filename.empty())
+	{
+		LOGERR("No file specified.\n");
+		return -1;
+	}
 
-    // We're going to jump to this page first, like a loading page
-    gui_changePage(pageName);
+	// We're going to jump to this page first, like a loading page
+	gui_changePage(pageName);
 
-    int fd = -1;
-    ZipArchive zip;
+	int fd = -1;
+	ZipArchive zip;
 
-    if (!PartitionManager.Mount_By_Path(filename, true))
+	if (!PartitionManager.Mount_By_Path(filename, true))
 		return -1;
 
 	if (mzOpenZipArchive(filename.c_str(), &zip))
-    {
-        LOGERR("Unable to open zip file.\n");
-        return -1;
-    }
+	{
+		LOGERR("Unable to open zip file.\n");
+		return -1;
+	}
 
-    // Check the zip to see if it has a custom installer theme
+	// Check the zip to see if it has a custom installer theme
 	const ZipEntry* twrp = mzFindZipEntry(&zip, "META-INF/teamwin/twrp.zip");
-    if (twrp != NULL)
-    {
-        unlink("/tmp/twrp.zip");
-        fd = creat("/tmp/twrp.zip", 0666);
-    }
-    if (fd >= 0 && twrp != NULL && 
-        mzExtractZipEntryToFile(&zip, twrp, fd) && 
-        !PageManager::LoadPackage("install", "/tmp/twrp.zip", "main"))
-    {
-        mzCloseZipArchive(&zip);
+	if (twrp != NULL)
+	{
+		unlink("/tmp/twrp.zip");
+		fd = creat("/tmp/twrp.zip", 0666);
+	}
+	if (fd >= 0 && twrp != NULL &&
+		mzExtractZipEntryToFile(&zip, twrp, fd) &&
+		!PageManager::LoadPackage("install", "/tmp/twrp.zip", "main"))
+	{
+		mzCloseZipArchive(&zip);
 		PageManager::SelectPackage("install");
-        gui_changePage("main");
-    }
-    else
-    {
-        // In this case, we just use the default page
-        mzCloseZipArchive(&zip);
+		gui_changePage("main");
+	}
+	else
+	{
+		// In this case, we just use the default page
+		mzCloseZipArchive(&zip);
 		gui_changePage(pageName);
-    }
-    if (fd >= 0)
-        close(fd);
+	}
+	if (fd >= 0)
+		close(fd);
 
 	if (simulate) {
 		simulate_progress_bar();
@@ -237,20 +237,20 @@
 		}
 	}
 
-    // Done
-    DataManager::SetValue("ui_progress", 100);
-    DataManager::SetValue("ui_progress", 0);
-    return ret_val;
+	// Done
+	DataManager::SetValue("ui_progress", 100);
+	DataManager::SetValue("ui_progress", 0);
+	return ret_val;
 }
 
 int GUIAction::doActions()
 {
-	if (mActions.size() < 1)    return -1;
-    if (mActions.size() == 1)
+	if (mActions.size() < 1)	return -1;
+	if (mActions.size() == 1)
 		return doAction(mActions.at(0), 0);
 
-    // For multi-action, we always use a thread
-    pthread_t t;
+	// For multi-action, we always use a thread
+	pthread_t t;
 	pthread_attr_t tattr;
 
 	if (pthread_attr_init(&tattr)) {
@@ -271,7 +271,7 @@
 	}
 	*/
 	int ret = pthread_create(&t, &tattr, thread_start, this);
-    if (ret) {
+	if (ret) {
 		LOGERR("Unable to create more threads for actions... continuing in same thread! %i\n", ret);
 		thread_start(this);
 	} else {
@@ -284,30 +284,30 @@
 		return -1;
 	}
 
-    return 0;
+	return 0;
 }
 
 void* GUIAction::thread_start(void *cookie)
 {
-    GUIAction* ourThis = (GUIAction*) cookie;
+	GUIAction* ourThis = (GUIAction*) cookie;
 
 	DataManager::SetValue(TW_ACTION_BUSY, 1);
 
-    if (ourThis->mActions.size() > 1)
-    {
-        std::vector<Action>::iterator iter;
-        for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++)
-            ourThis->doAction(*iter, 1);
-    }
-    else
-    {
-        ourThis->doAction(ourThis->mActions.at(0), 1);
-    }
+	if (ourThis->mActions.size() > 1)
+	{
+		std::vector<Action>::iterator iter;
+		for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++)
+			ourThis->doAction(*iter, 1);
+	}
+	else
+	{
+		ourThis->doAction(ourThis->mActions.at(0), 1);
+	}
 	int check = 0;
 	DataManager::GetValue("tw_background_thread_running", check);
 	if (check == 0)
 		DataManager::SetValue(TW_ACTION_BUSY, 0);
-    return NULL;
+	return NULL;
 }
 
 void GUIAction::operation_start(const string operation_name)
@@ -357,7 +357,7 @@
 
 	if (function == "reboot")
 	{
-	        //curtainClose(); this sometimes causes a crash
+			//curtainClose(); this sometimes causes a crash
 
 		sync();
 		DataManager::SetValue("tw_gui_done", 1);
@@ -365,25 +365,25 @@
 
 		return 0;
 	}
-    if (function == "home")
-    {
-        PageManager::SelectPackage("TWRP");
-        gui_changePage("main");
-        return 0;
-    }
-
-    if (function == "key")
-    {
-        PageManager::NotifyKey(getKeyByName(arg));
-        return 0;
-    }
-
-    if (function == "page") {
-		std::string page_name = gui_parse_text(arg);
-        return gui_changePage(page_name);
+	if (function == "home")
+	{
+		PageManager::SelectPackage("TWRP");
+		gui_changePage("main");
+		return 0;
 	}
 
-    if (function == "reload") {
+	if (function == "key")
+	{
+		PageManager::NotifyKey(getKeyByName(arg));
+		return 0;
+	}
+
+	if (function == "page") {
+		std::string page_name = gui_parse_text(arg);
+		return gui_changePage(page_name);
+	}
+
+	if (function == "reload") {
 		int check = 0, ret_val = 0;
 		std::string theme_path;
 
@@ -405,85 +405,85 @@
 				ret_val = 1;
 			}
 		}
-        operation_end(ret_val, simulate);
+		operation_end(ret_val, simulate);
 		return 0;
 	}
 
-    if (function == "readBackup")
-    {
+	if (function == "readBackup")
+	{
 		string Restore_Name;
 		DataManager::GetValue("tw_restore", Restore_Name);
 		PartitionManager.Set_Restore_Files(Restore_Name);
-        return 0;
-    }
+		return 0;
+	}
 
-    if (function == "set")
-    {
-        if (arg.find('=') != string::npos)
-        {
-            string varName = arg.substr(0, arg.find('='));
-            string value = arg.substr(arg.find('=') + 1, string::npos);
+	if (function == "set")
+	{
+		if (arg.find('=') != string::npos)
+		{
+			string varName = arg.substr(0, arg.find('='));
+			string value = arg.substr(arg.find('=') + 1, string::npos);
 
-            DataManager::GetValue(value, value);
-            DataManager::SetValue(varName, value);
-        }
-        else
-            DataManager::SetValue(arg, "1");
-        return 0;
-    }
-    if (function == "clear")
-    {
-        DataManager::SetValue(arg, "0");
-        return 0;
-    }
+			DataManager::GetValue(value, value);
+			DataManager::SetValue(varName, value);
+		}
+		else
+			DataManager::SetValue(arg, "1");
+		return 0;
+	}
+	if (function == "clear")
+	{
+		DataManager::SetValue(arg, "0");
+		return 0;
+	}
 
-    if (function == "mount")
-    {
-        if (arg == "usb")
-        {
-            DataManager::SetValue(TW_ACTION_BUSY, 1);
+	if (function == "mount")
+	{
+		if (arg == "usb")
+		{
+			DataManager::SetValue(TW_ACTION_BUSY, 1);
 			if (!simulate)
 				PartitionManager.usb_storage_enable();
 			else
 				gui_print("Simulating actions...\n");
-        }
-        else if (!simulate)
-        {
-            string cmd;
+		}
+		else if (!simulate)
+		{
+			string cmd;
 			if (arg == "EXTERNAL")
 				PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true);
 			else if (arg == "INTERNAL")
 				PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true);
 			else
 				PartitionManager.Mount_By_Path(arg, true);
-        } else
+		} else
 			gui_print("Simulating actions...\n");
-        return 0;
-    }
+		return 0;
+	}
 
-    if (function == "umount" || function == "unmount")
-    {
-        if (arg == "usb")
-        {
-            if (!simulate)
+	if (function == "umount" || function == "unmount")
+	{
+		if (arg == "usb")
+		{
+			if (!simulate)
 				PartitionManager.usb_storage_disable();
 			else
 				gui_print("Simulating actions...\n");
 			DataManager::SetValue(TW_ACTION_BUSY, 0);
-        }
-        else if (!simulate)
-        {
-            string cmd;
+		}
+		else if (!simulate)
+		{
+			string cmd;
 			if (arg == "EXTERNAL")
 				PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true);
 			else if (arg == "INTERNAL")
 				PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true);
 			else
 				PartitionManager.UnMount_By_Path(arg, true);
-        } else
+		} else
 			gui_print("Simulating actions...\n");
-        return 0;
-    }
+		return 0;
+	}
 	
 	if (function == "restoredefaultsettings")
 	{
@@ -519,20 +519,20 @@
 	if (function == "compute" || function == "addsubtract")
 	{
 		if (arg.find("+") != string::npos)
-        {
-            string varName = arg.substr(0, arg.find('+'));
-            string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
+		{
+			string varName = arg.substr(0, arg.find('+'));
+			string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
 			int amount_to_add = atoi(string_to_add.c_str());
 			int value;
 
 			DataManager::GetValue(varName, value);
-            DataManager::SetValue(varName, value + amount_to_add);
+			DataManager::SetValue(varName, value + amount_to_add);
 			return 0;
-        }
+		}
 		if (arg.find("-") != string::npos)
-        {
-            string varName = arg.substr(0, arg.find('-'));
-            string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
+		{
+			string varName = arg.substr(0, arg.find('-'));
+			string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
 			int amount_to_subtract = atoi(string_to_subtract.c_str());
 			int value;
 
@@ -540,9 +540,9 @@
 			value -= amount_to_subtract;
 			if (value <= 0)
 				value = 0;
-            DataManager::SetValue(varName, value);
+			DataManager::SetValue(varName, value);
 			return 0;
-        }
+		}
 		if (arg.find("*") != string::npos)
 		{
 			string varName = arg.substr(0, arg.find('*'));
@@ -653,11 +653,11 @@
 	}
 	
 	if (function == "overlay")
-        return gui_changeOverlay(arg);
+		return gui_changeOverlay(arg);
 
 	if (function == "queuezip")
-    {
-        if (zip_queue_index >= 10) {
+	{
+		if (zip_queue_index >= 10) {
 			gui_print("Maximum zip queue reached!\n");
 			return 0;
 		}
@@ -670,8 +670,8 @@
 	}
 
 	if (function == "cancelzip")
-    {
-        if (zip_queue_index <= 0) {
+	{
+		if (zip_queue_index <= 0) {
 			gui_print("Minimum zip queue reached!\n");
 			return 0;
 		} else {
@@ -696,9 +696,9 @@
 		return 0;
 	}
 
-    if (isThreaded)
-    {
-        if (function == "fileexists")
+	if (isThreaded)
+	{
+		if (function == "fileexists")
 		{
 			struct stat st;
 			string newpath = arg + "/.";
@@ -712,13 +712,13 @@
 		}
 
 		if (function == "flash")
-        {
+		{
 			int i, ret_val = 0, wipe_cache = 0;
 
 			for (i=0; i<zip_queue_index; i++) {
 				operation_start("Flashing");
-		        DataManager::SetValue("tw_filename", zip_queue[i]);
-		        DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
+				DataManager::SetValue("tw_filename", zip_queue[i]);
+				DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
 
 				ret_val = flash_zip(zip_queue[i], arg, simulate, &wipe_cache);
 				if (ret_val != 0) {
@@ -751,12 +751,12 @@
 			}
 			PartitionManager.Update_System_Details();
 			operation_end(ret_val, simulate);
-            return 0;
-        }
-        if (function == "wipe")
-        {
-            operation_start("Format");
-            DataManager::SetValue("tw_partition", arg);
+			return 0;
+		}
+		if (function == "wipe")
+		{
+			operation_start("Format");
+			DataManager::SetValue("tw_partition", arg);
 
 			int ret_val = false;
 
@@ -863,9 +863,9 @@
 				ret_val = 0; // 0 is success
 			else
 				ret_val = 1; // 1 is failure
-            operation_end(ret_val, simulate);
-            return 0;
-        }
+			operation_end(ret_val, simulate);
+			return 0;
+		}
 		if (function == "refreshsizes")
 		{
 			operation_start("Refreshing Sizes");
@@ -876,9 +876,9 @@
 			operation_end(0, simulate);
 			return 0;
 		}
-        if (function == "nandroid")
-        {
-            operation_start("Nandroid");
+		if (function == "nandroid")
+		{
+			operation_start("Nandroid");
 			int ret = 0;
 
 			if (simulate) {
@@ -910,13 +910,13 @@
 				ret = 1; // 1 for failure
 			else
 				ret = 0; // 0 for success
-            operation_end(ret, simulate);
+			operation_end(ret, simulate);
 			return 0;
-        }
+		}
 		if (function == "fixpermissions")
 		{
 			operation_start("Fix Permissions");
-            LOGINFO("fix permissions started!\n");
+			LOGINFO("fix permissions started!\n");
 			if (simulate) {
 				simulate_progress_bar();
 			} else {
@@ -927,9 +927,9 @@
 			}
 			return 0;
 		}
-        if (function == "dd")
-        {
-            operation_start("imaging");
+		if (function == "dd")
+		{
+			operation_start("imaging");
 
 			if (simulate) {
 				simulate_progress_bar();
@@ -938,9 +938,9 @@
 				string cmd = "dd " + arg;
 				TWFunc::Exec_Cmd(cmd, result);
 			}
-            operation_end(0, simulate);
-            return 0;
-        }
+			operation_end(0, simulate);
+			return 0;
+		}
 		if (function == "partitionsd")
 		{
 			operation_start("Partition SD Card");
@@ -1292,26 +1292,26 @@
 			operation_end(op_status, simulate);
 			return 0;
 		}
-    }
-    else
-    {
+	}
+	else
+	{
 		pthread_t t;
 		pthread_create(&t, NULL, thread_start, this);
-        return 0;
-    }
+		return 0;
+	}
 	LOGERR("Unknown action '%s'\n", function.c_str());
-    return -1;
+	return -1;
 }
 
 int GUIAction::getKeyByName(std::string key)
 {
-    if (key == "home")          return KEY_HOME;
-    else if (key == "menu")     return KEY_MENU;
-    else if (key == "back")     return KEY_BACK;
-    else if (key == "search")   return KEY_SEARCH;
-    else if (key == "voldown")  return KEY_VOLUMEDOWN;
-    else if (key == "volup")    return KEY_VOLUMEUP;
-    else if (key == "power") {
+	if (key == "home")			return KEY_HOME;
+	else if (key == "menu")		return KEY_MENU;
+	else if (key == "back")	 	return KEY_BACK;
+	else if (key == "search")	return KEY_SEARCH;
+	else if (key == "voldown")	return KEY_VOLUMEDOWN;
+	else if (key == "volup")	return KEY_VOLUMEUP;
+	else if (key == "power") {
 		int ret_val;
 		DataManager::GetValue(TW_POWER_BUTTON, ret_val);
 		if (!ret_val)
@@ -1320,7 +1320,7 @@
 			return ret_val;
 	}
 
-    return atol(key.c_str());
+	return atol(key.c_str());
 }
 
 void* GUIAction::command_thread(void *cookie)
diff --git a/gui/animation.cpp b/gui/animation.cpp
index 77d7b54..8c92278 100644
--- a/gui/animation.cpp
+++ b/gui/animation.cpp
@@ -28,109 +28,109 @@
 
 GUIAnimation::GUIAnimation(xml_node<>* node)
 {
-    xml_node<>* child;
-    xml_attribute<>* attr;
+	xml_node<>* child;
+	xml_attribute<>* attr;
 
-    mAnimation = NULL;
-    mFrame = 1;
-    mFPS = 1;
-    mLoop = -1;
-    mRender = 1;
-    mUpdateCount = 0;
+	mAnimation = NULL;
+	mFrame = 1;
+	mFPS = 1;
+	mLoop = -1;
+	mRender = 1;
+	mUpdateCount = 0;
 
-    if (!node)  return;
+	if (!node)  return;
 
-    child = node->first_node("resource");
-    if (child)
-    {
-        attr = child->first_attribute("name");
-        if (attr)
-            mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
-    }
+	child = node->first_node("resource");
+	if (child)
+	{
+		attr = child->first_attribute("name");
+		if (attr)
+			mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
+	}
 
-    // Load the placement
-    LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
+	// Load the placement
+	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
 
-    child = node->first_node("speed");
-    if (child)
-    {
-        attr = child->first_attribute("fps");
-        if (attr)
-            mFPS = atoi(attr->value());
-        attr = child->first_attribute("render");
-        if (attr)
-            mRender = atoi(attr->value());
-    }
-    if (mFPS > 30)  mFPS = 30;
+	child = node->first_node("speed");
+	if (child)
+	{
+		attr = child->first_attribute("fps");
+		if (attr)
+			mFPS = atoi(attr->value());
+		attr = child->first_attribute("render");
+		if (attr)
+			mRender = atoi(attr->value());
+	}
+	if (mFPS > 30)  mFPS = 30;
 
-    child = node->first_node("loop");
-    if (child)
-    {
-        attr = child->first_attribute("frame");
-        if (attr)
-            mLoop = atoi(attr->value()) - 1;
-        attr = child->first_attribute("start");
-        if (attr)
-            mFrame = atoi(attr->value());
-    }
+	child = node->first_node("loop");
+	if (child)
+	{
+		attr = child->first_attribute("frame");
+		if (attr)
+			mLoop = atoi(attr->value()) - 1;
+		attr = child->first_attribute("start");
+		if (attr)
+			mFrame = atoi(attr->value());
+	}
 
-    // Fetch the render sizes
-    if (mAnimation && mAnimation->GetResource())
-    {
-        mRenderW = gr_get_width(mAnimation->GetResource());
-        mRenderH = gr_get_height(mAnimation->GetResource());
+	// Fetch the render sizes
+	if (mAnimation && mAnimation->GetResource())
+	{
+		mRenderW = gr_get_width(mAnimation->GetResource());
+		mRenderH = gr_get_height(mAnimation->GetResource());
 
-        // Adjust for placement
-        if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
-        {
-            if (mPlacement == CENTER)
-                mRenderX -= (mRenderW / 2);
-            else
-                mRenderX -= mRenderW;
-        }
-        if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
-        {
-            if (mPlacement == CENTER)
-                mRenderY -= (mRenderH / 2);
-            else
-                mRenderY -= mRenderH;
-        }
-        SetPlacement(TOP_LEFT);
-    }
+		// Adjust for placement
+		if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
+		{
+			if (mPlacement == CENTER)
+				mRenderX -= (mRenderW / 2);
+			else
+				mRenderX -= mRenderW;
+		}
+		if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
+		{
+			if (mPlacement == CENTER)
+				mRenderY -= (mRenderH / 2);
+			else
+				mRenderY -= mRenderH;
+		}
+		SetPlacement(TOP_LEFT);
+	}
 }
 
 int GUIAnimation::Render(void)
 {
-    if (!mAnimation || !mAnimation->GetResource(mFrame))      return -1;
+	if (!mAnimation || !mAnimation->GetResource(mFrame))	return -1;
 
-    gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
-    return 0;
+	gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+	return 0;
 }
 
 int GUIAnimation::Update(void)
 {
-    if (!mAnimation)        return -1;
+	if (!mAnimation)		return -1;
 
-    // Handle the "end-of-animation" state
-    if (mLoop == -2)        return 0;
+	// Handle the "end-of-animation" state
+	if (mLoop == -2)		return 0;
 
-    // Determine if we need the next frame yet...
-    if (++mUpdateCount > 30 / mFPS)
-    {
-        mUpdateCount = 0;
-        if (++mFrame >= mAnimation->GetResourceCount())
-        {
-            if (mLoop < 0)
-            {
-                mFrame = mAnimation->GetResourceCount() - 1;
-                mLoop = -2;
-            }
-            else
-                mFrame = mLoop;
-        }
-        if (mRender == 2)   return 2;
-        return (Render() == 0 ? 1 : -1);
-    }
-    return 0;
+	// Determine if we need the next frame yet...
+	if (++mUpdateCount > 30 / mFPS)
+	{
+		mUpdateCount = 0;
+		if (++mFrame >= mAnimation->GetResourceCount())
+		{
+			if (mLoop < 0)
+			{
+				mFrame = mAnimation->GetResourceCount() - 1;
+				mLoop = -2;
+			}
+			else
+				mFrame = mLoop;
+		}
+		if (mRender == 2)	return 2;
+		return (Render() == 0 ? 1 : -1);
+	}
+	return 0;
 }
 
diff --git a/gui/blanktimer.hpp b/gui/blanktimer.hpp
index 60d5b1b..01c1dfb 100644
--- a/gui/blanktimer.hpp
+++ b/gui/blanktimer.hpp
@@ -24,31 +24,35 @@
 
 using namespace std;
 
-class blanktimer {
-	public:
-		blanktimer(void);
-		int setTimerThread(void);
-		void resetTimerAndUnblank(void);
-		void setTime(int newtime);
-		bool IsScreenOff();
+class blanktimer
+{
+public:
+	blanktimer(void);
 
-	private:
-		void setConBlank(int blank);
-		void setTimer(void);
-		timespec getTimer(void);
-		int getBrightness(void);
-		int setBrightness(int brightness);
-		int setBlankTimer(void);
-		int setClockTimer(void);
-		typedef int (blanktimer::*ThreadPtr)(void);
-		typedef void* (*PThreadPtr)(void*);
-		pthread_mutex_t conblankmutex;
-		pthread_mutex_t timermutex;
-		int conblank;
-		timespec btimer;
-		unsigned long long sleepTimer;
-		int orig_brightness;
-		bool screenoff;
+	int setTimerThread(void);
+	void resetTimerAndUnblank(void);
+	void setTime(int newtime);
+	bool IsScreenOff();
+
+private:
+	typedef int (blanktimer::*ThreadPtr)(void);
+	typedef void* (*PThreadPtr)(void*);
+
+	void setConBlank(int blank);
+	void setTimer(void);
+	timespec getTimer(void);
+	int getBrightness(void);
+	int setBrightness(int brightness);
+	int setBlankTimer(void);
+	int setClockTimer(void);
+
+	pthread_mutex_t conblankmutex;
+	pthread_mutex_t timermutex;
+	int conblank;
+	timespec btimer;
+	unsigned long long sleepTimer;
+	int orig_brightness;
+	bool screenoff;
 };
 
 extern blanktimer blankTimer;
diff --git a/gui/button.cpp b/gui/button.cpp
index af7d07b..9fc85a0 100644
--- a/gui/button.cpp
+++ b/gui/button.cpp
@@ -42,42 +42,42 @@
 #include "objects.hpp"
 
 GUIButton::GUIButton(xml_node<>* node)
-    : Conditional(node)
+	: Conditional(node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mButtonImg = NULL;
-    mButtonIcon = NULL;
-    mButtonLabel = NULL;
-    mAction = NULL;
-    mRendered = false;
+	mButtonImg = NULL;
+	mButtonIcon = NULL;
+	mButtonLabel = NULL;
+	mAction = NULL;
+	mRendered = false;
 	hasHighlightColor = false;
 	renderHighlight = false;
 	hasFill = false;
 
-    if (!node)  return;
+	if (!node)  return;
 
-    // Three of the four can be loaded directly from the node
-    mButtonImg = new GUIImage(node);
-    mButtonLabel = new GUIText(node);
-    mAction = new GUIAction(node);
+	// Three of the four can be loaded directly from the node
+	mButtonImg = new GUIImage(node);
+	mButtonLabel = new GUIText(node);
+	mAction = new GUIAction(node);
 
-    if (mButtonImg->Render() < 0)
-    {
-        delete mButtonImg;
-        mButtonImg = NULL;
-    }
-    if (mButtonLabel->Render() < 0)
-    {
-        delete mButtonLabel;
-        mButtonLabel = NULL;
-    }
+	if (mButtonImg->Render() < 0)
+	{
+		delete mButtonImg;
+		mButtonImg = NULL;
+	}
+	if (mButtonLabel->Render() < 0)
+	{
+		delete mButtonLabel;
+		mButtonLabel = NULL;
+	}
 	// Load fill if it exists
 	memset(&mFillColor, 0, sizeof(COLOR));
 	child = node->first_node("fill");
-    if (child)
-    {
+	if (child)
+	{
 		attr = child->first_attribute("color");
 		if (attr) {
 			hasFill = true;
@@ -89,14 +89,14 @@
 		LOGERR("No image resource or fill specified for button.\n");
 	}
 
-    // The icon is a special case
-    child = node->first_node("icon");
-    if (child)
-    {
-        attr = child->first_attribute("resource");
-        if (attr)
-            mButtonIcon = PageManager::FindResource(attr->value());
-    }
+	// The icon is a special case
+	child = node->first_node("icon");
+	if (child)
+	{
+		attr = child->first_attribute("resource");
+		if (attr)
+			mButtonIcon = PageManager::FindResource(attr->value());
+	}
 
 	memset(&mHighlightColor, 0, sizeof(COLOR));
 	child = node->first_node("highlight");
@@ -109,43 +109,43 @@
 		}
 	}
 
-    int x, y, w, h;
-    if (mButtonImg) {
+	int x, y, w, h;
+	if (mButtonImg) {
 		mButtonImg->GetRenderPos(x, y, w, h);
 	} else if (hasFill) {
 		LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
 	}
 	SetRenderPos(x, y, w, h);
-    return;
+	return;
 }
 
 GUIButton::~GUIButton()
 {
-    if (mButtonImg)     delete mButtonImg;
-    if (mButtonLabel)   delete mButtonLabel;
-    if (mAction)        delete mAction;
-	if (mButtonIcon)    delete mButtonIcon;
+	if (mButtonImg)	 	delete mButtonImg;
+	if (mButtonLabel)   delete mButtonLabel;
+	if (mAction)		delete mAction;
+	if (mButtonIcon)	delete mButtonIcon;
 }
 
 int GUIButton::Render(void)
 {
-    if (!isConditionTrue())
-    {
-        mRendered = false;
-        return 0;
-    }
+	if (!isConditionTrue())
+	{
+		mRendered = false;
+		return 0;
+	}
 
-    int ret = 0;
+	int ret = 0;
 
-    if (mButtonImg)     ret = mButtonImg->Render();
-    if (ret < 0)        return ret;
+	if (mButtonImg)	 ret = mButtonImg->Render();
+	if (ret < 0)		return ret;
 	if (hasFill) {
 		gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha);
 		gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
 	}
-    if (mButtonIcon && mButtonIcon->GetResource())
-        gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
-    if (mButtonLabel) {
+	if (mButtonIcon && mButtonIcon->GetResource())
+		gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
+	if (mButtonLabel) {
 		int w, h;
 		mButtonLabel->GetCurrentBounds(w, h);
 		if (w != mTextW) {
@@ -163,109 +163,109 @@
 			mButtonLabel->SetRenderPos(mTextX, mTextY);
 		}
 		ret = mButtonLabel->Render();
-		if (ret < 0)        return ret;
+		if (ret < 0)		return ret;
 	}
 	if (renderHighlight && hasHighlightColor) {
 		gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
 		gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
 	}
-    mRendered = true;
-    return ret;
+	mRendered = true;
+	return ret;
 }
 
 int GUIButton::Update(void)
 {
-    if (!isConditionTrue())     return (mRendered ? 2 : 0);
-    if (!mRendered)             return 2;
+	if (!isConditionTrue())	return (mRendered ? 2 : 0);
+	if (!mRendered)			return 2;
 
-    int ret = 0, ret2 = 0;
+	int ret = 0, ret2 = 0;
 
-    if (mButtonImg)             ret = mButtonImg->Update();
-    if (ret < 0)            return ret;
+	if (mButtonImg)			ret = mButtonImg->Update();
+	if (ret < 0)			return ret;
 
-    if (ret == 0)
-    {
-        if (mButtonLabel) {
+	if (ret == 0)
+	{
+		if (mButtonLabel) {
 			ret2 = mButtonLabel->Update();
-			if (ret2 < 0)       return ret2;
-			if (ret2 > ret)     ret = ret2;
+			if (ret2 < 0)	return ret2;
+			if (ret2 > ret)	ret = ret2;
 		}
-    }
-    else if (ret == 1)
-    {
-        // The button re-rendered, so everyone else is a render
-        if (mButtonIcon && mButtonIcon->GetResource())
-            gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
-        if (mButtonLabel)   ret = mButtonLabel->Render();
-        if (ret < 0)        return ret;
-        ret = 1;
-    }
-    else
-    {
-        // Aparently, the button needs a background update
-        ret = 2;
-    }
-    return ret;
+	}
+	else if (ret == 1)
+	{
+		// The button re-rendered, so everyone else is a render
+		if (mButtonIcon && mButtonIcon->GetResource())
+			gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
+		if (mButtonLabel)   ret = mButtonLabel->Render();
+		if (ret < 0)		return ret;
+		ret = 1;
+	}
+	else
+	{
+		// Aparently, the button needs a background update
+		ret = 2;
+	}
+	return ret;
 }
 
 int GUIButton::SetRenderPos(int x, int y, int w, int h)
 {
-    mRenderX = x;
-    mRenderY = y;
-    if (w || h)
-    {
-        mRenderW = w;
-        mRenderH = h;
-    }
+	mRenderX = x;
+	mRenderY = y;
+	if (w || h)
+	{
+		mRenderW = w;
+		mRenderH = h;
+	}
 
-    mIconW = 0;     mIconH = 0;
-    if (mButtonIcon && mButtonIcon->GetResource())
-    {
-        mIconW = gr_get_width(mButtonIcon->GetResource());
-        mIconH = gr_get_height(mButtonIcon->GetResource());
-    }
+	mIconW = 0;	 mIconH = 0;
+	if (mButtonIcon && mButtonIcon->GetResource())
+	{
+		mIconW = gr_get_width(mButtonIcon->GetResource());
+		mIconH = gr_get_height(mButtonIcon->GetResource());
+	}
 
-    mTextH = 0;
-    mTextW = 0;
-    mIconX = mRenderX + ((mRenderW - mIconW) / 2);
-    if (mButtonLabel)   mButtonLabel->GetCurrentBounds(mTextW, mTextH);
-    if (mTextW)
-    {
-        // As a special case, we'll allow large text which automatically moves it to the right.
-        if (mTextW > mRenderW)
-        {
-            mTextX = mRenderW + mRenderX + 5;
-            mRenderW += mTextW + 5;
-        }
-        else
-        {
-            mTextX = mRenderX + ((mRenderW - mTextW) / 2);
-        }
-    }
+	mTextH = 0;
+	mTextW = 0;
+	mIconX = mRenderX + ((mRenderW - mIconW) / 2);
+	if (mButtonLabel)   mButtonLabel->GetCurrentBounds(mTextW, mTextH);
+	if (mTextW)
+	{
+		// As a special case, we'll allow large text which automatically moves it to the right.
+		if (mTextW > mRenderW)
+		{
+			mTextX = mRenderW + mRenderX + 5;
+			mRenderW += mTextW + 5;
+		}
+		else
+		{
+			mTextX = mRenderX + ((mRenderW - mTextW) / 2);
+		}
+	}
 
-    if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
-    {
-        mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
-        mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
-    }
-    else
-    {
-        int divisor = mRenderH - (mIconH + mTextH);
-        mIconY = mRenderY + (divisor / 3);
-        mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
-    }
+	if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
+	{
+		mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
+		mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
+	}
+	else
+	{
+		int divisor = mRenderH - (mIconH + mTextH);
+		mIconY = mRenderY + (divisor / 3);
+		mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
+	}
 
-    if (mButtonLabel)   mButtonLabel->SetRenderPos(mTextX, mTextY);
-    if (mAction)        mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
-    SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
-    return 0;
+	if (mButtonLabel)   mButtonLabel->SetRenderPos(mTextX, mTextY);
+	if (mAction)		mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
+	SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
+	return 0;
 }
 
 int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
 	static int last_state = 0;
 
-	if (!isConditionTrue())     return -1;
+	if (!isConditionTrue())	 return -1;
 	if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) {
 		if (last_state == 1) {
 			last_state = 0;
@@ -289,6 +289,5 @@
 	}
 	if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH)
 		return 0;
-    return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
+	return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
 }
-
diff --git a/gui/checkbox.cpp b/gui/checkbox.cpp
index 077d5e2..b6d5e63 100644
--- a/gui/checkbox.cpp
+++ b/gui/checkbox.cpp
@@ -26,63 +26,64 @@
 #include "objects.hpp"
 
 GUICheckbox::GUICheckbox(xml_node<>* node)
-    : Conditional(node)
+	: Conditional(node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mChecked = NULL;
-    mUnchecked = NULL;
-    mLabel = NULL;
-    mRendered = false;
+	mChecked = NULL;
+	mUnchecked = NULL;
+	mLabel = NULL;
+	mRendered = false;
 
-    mLastState = 0;
+	mLastState = 0;
 
-    if (!node)  return;
+	if (!node)
+		return;
 
-    // The label can be loaded directly
-    mLabel = new GUIText(node);
+	// The label can be loaded directly
+	mLabel = new GUIText(node);
 
-    // Read the check states
-    child = node->first_node("image");
-    if (child)
-    {
-        attr = child->first_attribute("checked");
-        if (attr)
-            mChecked = PageManager::FindResource(attr->value());
-        attr = child->first_attribute("unchecked");
-        if (attr)
-            mUnchecked = PageManager::FindResource(attr->value());
-    }
+	// Read the check states
+	child = node->first_node("image");
+	if (child)
+	{
+		attr = child->first_attribute("checked");
+		if (attr)
+			mChecked = PageManager::FindResource(attr->value());
+		attr = child->first_attribute("unchecked");
+		if (attr)
+			mUnchecked = PageManager::FindResource(attr->value());
+	}
 
-    // Get the variable data
-    child = node->first_node("data");
-    if (child)
-    {
-        attr = child->first_attribute("variable");
-        if (attr)
-            mVarName = attr->value();
-        attr = child->first_attribute("default");
-        if (attr)
-            DataManager::SetValue(mVarName, attr->value());
-    }
+	// Get the variable data
+	child = node->first_node("data");
+	if (child)
+	{
+		attr = child->first_attribute("variable");
+		if (attr)
+			mVarName = attr->value();
+		attr = child->first_attribute("default");
+		if (attr)
+			DataManager::SetValue(mVarName, attr->value());
+	}
 
-    mCheckW = 0;    mCheckH = 0;
-    if (mChecked && mChecked->GetResource())
-    {
-        mCheckW = gr_get_width(mChecked->GetResource());
-        mCheckH = gr_get_height(mChecked->GetResource());
-    }
-    else if (mUnchecked && mUnchecked->GetResource())
-    {
-        mCheckW = gr_get_width(mUnchecked->GetResource());
-        mCheckH = gr_get_height(mUnchecked->GetResource());
-    }
+	mCheckW = 0;	mCheckH = 0;
+	if (mChecked && mChecked->GetResource())
+	{
+		mCheckW = gr_get_width(mChecked->GetResource());
+		mCheckH = gr_get_height(mChecked->GetResource());
+	}
+	else if (mUnchecked && mUnchecked->GetResource())
+	{
+		mCheckW = gr_get_width(mUnchecked->GetResource());
+		mCheckH = gr_get_height(mUnchecked->GetResource());
+	}
 
-    int x, y, w, h;
-    mLabel->GetRenderPos(x, y, w, h);
-    SetRenderPos(x, y, 0, 0);
-    return;
+	int x, y, w, h;
+	mLabel->GetRenderPos(x, y, w, h);
+	SetRenderPos(x, y, 0, 0);
+	return;
 }
 
 GUICheckbox::~GUICheckbox()
@@ -91,78 +92,81 @@
 
 int GUICheckbox::Render(void)
 {
-    if (!isConditionTrue())
-    {
-        mRendered = false;
-        return 0;
-    }
+	if (!isConditionTrue())
+	{
+		mRendered = false;
+		return 0;
+	}
 
-    int ret = 0;
-    int lastState = 0;
-    DataManager::GetValue(mVarName, lastState);
+	int ret = 0;
+	int lastState = 0;
+	DataManager::GetValue(mVarName, lastState);
 
-    if (lastState)
-    {
-        if (mChecked && mChecked->GetResource())
-            gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
-    }
-    else
-    {
-        if (mUnchecked && mUnchecked->GetResource())
-            gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
-    }
-    if (mLabel)     ret = mLabel->Render();
-    mLastState = lastState;
-    mRendered = true;
-    return ret;
+	if (lastState)
+	{
+		if (mChecked && mChecked->GetResource())
+			gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
+	}
+	else
+	{
+		if (mUnchecked && mUnchecked->GetResource())
+			gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
+	}
+	if (mLabel)
+		ret = mLabel->Render();
+	mLastState = lastState;
+	mRendered = true;
+	return ret;
 }
 
 int GUICheckbox::Update(void)
 {
-    if (!isConditionTrue())     return (mRendered ? 2 : 0);
-    if (!mRendered)             return 2;
+	if (!isConditionTrue())	return (mRendered ? 2 : 0);
+	if (!mRendered)			return 2;
 
-    int lastState = 0;
-    DataManager::GetValue(mVarName, lastState);
+	int lastState = 0;
+	DataManager::GetValue(mVarName, lastState);
 
-    if (lastState != mLastState)
-        return 2;
-    return 0;
+	if (lastState != mLastState)
+		return 2;
+	return 0;
 }
 
 int GUICheckbox::SetRenderPos(int x, int y, int w, int h)
 {
-    mRenderX = x;
-    mRenderY = y;
+	mRenderX = x;
+	mRenderY = y;
 
-    if (w || h)     return -1;
+	if (w || h)
+		return -1;
 
-    int textW, textH;
-    mLabel->GetCurrentBounds(textW, textH);
+	int textW, textH;
+	mLabel->GetCurrentBounds(textW, textH);
 
-    w = textW + mCheckW + 5;
-    mRenderW = w;
-    mRenderH = mCheckH;
+	w = textW + mCheckW + 5;
+	mRenderW = w;
+	mRenderH = mCheckH;
 
-    mTextX = mRenderX + mCheckW + 5;
-    mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
+	mTextX = mRenderX + mCheckW + 5;
+	mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
 
-    mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
-    SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
-    return 0;
+	mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
+	SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
+	return 0;
 }
 
 int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    if (!isConditionTrue())     return -1;
+	if (!isConditionTrue())
+		return -1;
 
-    if (state == TOUCH_RELEASE)
-    {
-        int lastState;
-        DataManager::GetValue(mVarName, lastState);
-        lastState = (lastState == 0) ? 1 : 0;
-        DataManager::SetValue(mVarName, lastState);
-    }
-    return 0;
+	if (state == TOUCH_RELEASE)
+	{
+		int lastState;
+		DataManager::GetValue(mVarName, lastState);
+		lastState = (lastState == 0) ? 1 : 0;
+		DataManager::SetValue(mVarName, lastState);
+	}
+	return 0;
 }
 
diff --git a/gui/conditional.cpp b/gui/conditional.cpp
index b3aba2d..5ea8d17 100644
--- a/gui/conditional.cpp
+++ b/gui/conditional.cpp
@@ -29,153 +29,156 @@
 
 Conditional::Conditional(xml_node<>* node)
 {
-    // Break out early, it's too hard to check if valid every step
-    if (!node)          return;
+	// Break out early, it's too hard to check if valid every step
+	if (!node)		return;
 
-    // First, get the action
-    xml_node<>* condition = node->first_node("conditions");
-    if (condition)  condition = condition->first_node("condition");
-    else            condition = node->first_node("condition");
+	// First, get the action
+	xml_node<>* condition = node->first_node("conditions");
+	if (condition)  condition = condition->first_node("condition");
+	else			condition = node->first_node("condition");
 
-    if (!condition)     return;
+	if (!condition)	return;
 
-    while (condition)
-    {
-        Condition cond;
+	while (condition)
+	{
+		Condition cond;
 
-        cond.mCompareOp = "=";
+		cond.mCompareOp = "=";
 
-        xml_attribute<>* attr;
-        attr = condition->first_attribute("var1");
-        if (attr)   cond.mVar1 = attr->value();
+		xml_attribute<>* attr;
+		attr = condition->first_attribute("var1");
+		if (attr)   cond.mVar1 = attr->value();
 
-        attr = condition->first_attribute("op");
-        if (attr)   cond.mCompareOp = attr->value();
+		attr = condition->first_attribute("op");
+		if (attr)   cond.mCompareOp = attr->value();
 
-        attr = condition->first_attribute("var2");
-        if (attr)   cond.mVar2 = attr->value();
-    
-        mConditions.push_back(cond);
+		attr = condition->first_attribute("var2");
+		if (attr)   cond.mVar2 = attr->value();
+	
+		mConditions.push_back(cond);
 
-        condition = condition->next_sibling("condition");
-    }
+		condition = condition->next_sibling("condition");
+	}
 }
 
 bool Conditional::IsConditionVariable(std::string var)
 {
-    std::vector<Condition>::iterator iter;
-    for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
-    {
-        if (iter->mVar1 == var)     return true;
-    }
-    return false;
+	std::vector<Condition>::iterator iter;
+	for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
+	{
+		if (iter->mVar1 == var)
+			return true;
+	}
+	return false;
 }
 
 bool Conditional::isConditionTrue()
 {
-    std::vector<Condition>::iterator iter;
-    for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
-    {
-        if (!isConditionTrue(&(*iter)))     return false;
-    }
-    return true;
+	std::vector<Condition>::iterator iter;
+	for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
+	{
+		if (!isConditionTrue(&(*iter)))
+			return false;
+	}
+	return true;
 }
 
 bool Conditional::isConditionTrue(Condition* condition)
 {
-    // This is used to hold the proper value of "true" based on the '!' NOT flag
-    bool bTrue = true;
+	// This is used to hold the proper value of "true" based on the '!' NOT flag
+	bool bTrue = true;
 
-    if (condition->mVar1.empty())      return bTrue;
+	if (condition->mVar1.empty())
+		return bTrue;
 
-    if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!')
-        bTrue = false;
+	if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!')
+		bTrue = false;
 
-    if (condition->mVar2.empty() && condition->mCompareOp != "modified")
-    {
-        if (!DataManager::GetStrValue(condition->mVar1).empty())
-            return bTrue;
+	if (condition->mVar2.empty() && condition->mCompareOp != "modified")
+	{
+		if (!DataManager::GetStrValue(condition->mVar1).empty())
+			return bTrue;
 
-        return !bTrue;
-    }
+		return !bTrue;
+	}
 
-    string var1, var2;
-    if (DataManager::GetValue(condition->mVar1, var1))
-        var1 = condition->mVar1;
-    if (DataManager::GetValue(condition->mVar2, var2))
-        var2 = condition->mVar2;
+	string var1, var2;
+	if (DataManager::GetValue(condition->mVar1, var1))
+		var1 = condition->mVar1;
+	if (DataManager::GetValue(condition->mVar2, var2))
+		var2 = condition->mVar2;
 
-    // This is a special case, we stat the file and that determines our result
-    if (var1 == "fileexists")
-    {
-        struct stat st;
-        if (stat(var2.c_str(), &st) == 0)
-            var2 = var1;
-        else
-            var2 = "FAILED";
-    }
-    if (var1 == "mounted")
-    {
-        if (isMounted(condition->mVar2))
-            var2 = var1;
-        else
-            var2 = "FAILED";
-    }
+	// This is a special case, we stat the file and that determines our result
+	if (var1 == "fileexists")
+	{
+		struct stat st;
+		if (stat(var2.c_str(), &st) == 0)
+			var2 = var1;
+		else
+			var2 = "FAILED";
+	}
+	if (var1 == "mounted")
+	{
+		if (isMounted(condition->mVar2))
+			var2 = var1;
+		else
+			var2 = "FAILED";
+	}
 
-    if (condition->mCompareOp.find('=') != string::npos && var1 == var2)
-        return bTrue;
+	if (condition->mCompareOp.find('=') != string::npos && var1 == var2)
+		return bTrue;
 
-    if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str())))
-        return bTrue;
+	if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str())))
+		return bTrue;
 
-    if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str())))
-        return bTrue;
+	if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str())))
+		return bTrue;
 
-    if (condition->mCompareOp == "modified")
-    {
-        // This is a hack to allow areas to reset the default value
-        if (var1.empty())
-        {
-            condition->mLastVal = var1;
-            return !bTrue;
-        }
+	if (condition->mCompareOp == "modified")
+	{
+		// This is a hack to allow areas to reset the default value
+		if (var1.empty())
+		{
+			condition->mLastVal = var1;
+			return !bTrue;
+		}
 
-        if (var1 != condition->mLastVal)
-            return bTrue;
-    }
+		if (var1 != condition->mLastVal)
+			return bTrue;
+	}
 
-    return !bTrue;
+	return !bTrue;
 }
 
 bool Conditional::isConditionValid()
 {
-    return !mConditions.empty();
+	return !mConditions.empty();
 }
 
 void Conditional::NotifyPageSet()
 {
-    std::vector<Condition>::iterator iter;
-    for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
-    {
-        if (iter->mCompareOp == "modified")
-        {
-            string val;
-    
-            // If this fails, val will not be set, which is perfect
-            if (DataManager::GetValue(iter->mVar1, val))
-            {
-                DataManager::SetValue(iter->mVar1, "");
-                DataManager::GetValue(iter->mVar1, val);
-            }
-            iter->mLastVal = val;
-        }
-    }
+	std::vector<Condition>::iterator iter;
+	for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
+	{
+		if (iter->mCompareOp == "modified")
+		{
+			string val;
+	
+			// If this fails, val will not be set, which is perfect
+			if (DataManager::GetValue(iter->mVar1, val))
+			{
+				DataManager::SetValue(iter->mVar1, "");
+				DataManager::GetValue(iter->mVar1, val);
+			}
+			iter->mLastVal = val;
+		}
+	}
 }
 
 bool Conditional::isMounted(string vol)
 {
 	FILE *fp;
-    char tmpOutput[255];
+	char tmpOutput[255];
 
 	if (strcmp(vol.c_str(), "EXTERNAL") == 0)
 		DataManager::GetValue(TW_EXTERNAL_MOUNT, vol);
@@ -184,19 +187,18 @@
 	fp = fopen("/proc/mounts", "rt");
 	while (fgets(tmpOutput,255,fp) != NULL)
 	{
-        char* mnt = tmpOutput;
-        while (*mnt > 32)               mnt++;
-        while (*mnt > 0 && *mnt <= 32)  mnt++;
-        char* pos = mnt;
-	    while (*pos > 32)   pos++;
-        *pos = 0;
-	    if (vol == mnt)
-        {
-            fclose(fp);
-            return true;
-        }
-    }
-    fclose(fp);
-    return false;
+		char* mnt = tmpOutput;
+		while (*mnt > 32)			mnt++;
+		while (*mnt > 0 && *mnt <= 32)	mnt++;
+		char* pos = mnt;
+		while (*pos > 32)   pos++;
+		*pos = 0;
+		if (vol == mnt)
+		{
+			fclose(fp);
+			return true;
+		}
+	}
+	fclose(fp);
+	return false;
 }
-
diff --git a/gui/console.cpp b/gui/console.cpp
index ee3b5e5..517a7c2 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -30,373 +30,374 @@
 
 extern "C" void gui_print(const char *fmt, ...)
 {
-    char buf[512];          // We're going to limit a single request to 512 bytes
+	char buf[512];		// We're going to limit a single request to 512 bytes
 
-    va_list ap;
-    va_start(ap, fmt);
-    vsnprintf(buf, 512, fmt, ap);
-    va_end(ap);
+	va_list ap;
+	va_start(ap, fmt);
+	vsnprintf(buf, 512, fmt, ap);
+	va_end(ap);
 
 	fputs(buf, stdout);
 
-    char *start, *next;
+	char *start, *next;
 
 	if (buf[0] == '\n' && strlen(buf) < 2) {
 		// This prevents the double lines bug seen in the console during zip installs
 		return;
 	}
 
-    for (start = next = buf; *next != '\0'; next++)
-    {
-        if (*next == '\n')
-        {
-            *next = '\0';
-            next++;
+	for (start = next = buf; *next != '\0'; next++)
+	{
+		if (*next == '\n')
+		{
+			*next = '\0';
+			next++;
 
-            std::string line = start;
-            gConsole.push_back(line);
-            start = next;
+			std::string line = start;
+			gConsole.push_back(line);
+			start = next;
 
 			// Handle the normal \n\0 case
-            if (*next == '\0')
+			if (*next == '\0')
 				return;
-        }
-    }
-    std::string line = start;
-    gConsole.push_back(line);
-    return;
+		}
+	}
+	std::string line = start;
+	gConsole.push_back(line);
+	return;
 }
 
 extern "C" void gui_print_overwrite(const char *fmt, ...)
 {
-    char buf[512];          // We're going to limit a single request to 512 bytes
+	char buf[512];		// We're going to limit a single request to 512 bytes
 
-    va_list ap;
-    va_start(ap, fmt);
-    vsnprintf(buf, 512, fmt, ap);
-    va_end(ap);
+	va_list ap;
+	va_start(ap, fmt);
+	vsnprintf(buf, 512, fmt, ap);
+	va_end(ap);
 
 	fputs(buf, stdout);
 
-    // Pop the last line, and we can continue
-    if (!gConsole.empty())   gConsole.pop_back();
+	// Pop the last line, and we can continue
+	if (!gConsole.empty())   gConsole.pop_back();
 
-    char *start, *next;
-    for (start = next = buf; *next != '\0'; next++)
-    {
-        if (*next == '\n')
-        {
-            *next = '\0';
-            next++;
-            
-            std::string line = start;
-            gConsole.push_back(line);
-            start = next;
+	char *start, *next;
+	for (start = next = buf; *next != '\0'; next++)
+	{
+		if (*next == '\n')
+		{
+			*next = '\0';
+			next++;
+			
+			std::string line = start;
+			gConsole.push_back(line);
+			start = next;
 
-            // Handle the normal \n\0 case
-            if (*next == '\0')
+			// Handle the normal \n\0 case
+			if (*next == '\0')
 				return;
-        }
-    }
-    std::string line = start;
-    gConsole.push_back(line);
-    return;
+		}
+	}
+	std::string line = start;
+	gConsole.push_back(line);
+	return;
 }
 
 GUIConsole::GUIConsole(xml_node<>* node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mFont = NULL;
-    mCurrentLine = -1;
-    memset(&mForegroundColor, 255, sizeof(COLOR));
-    memset(&mBackgroundColor, 0, sizeof(COLOR));
-    mBackgroundColor.alpha = 255;
-    memset(&mScrollColor, 0x08, sizeof(COLOR));
-    mScrollColor.alpha = 255;
-    mLastCount = 0;
-    mSlideout = 0;
-    mSlideoutState = hidden;
+	mFont = NULL;
+	mCurrentLine = -1;
+	memset(&mForegroundColor, 255, sizeof(COLOR));
+	memset(&mBackgroundColor, 0, sizeof(COLOR));
+	mBackgroundColor.alpha = 255;
+	memset(&mScrollColor, 0x08, sizeof(COLOR));
+	mScrollColor.alpha = 255;
+	mLastCount = 0;
+	mSlideout = 0;
+	mSlideoutState = hidden;
 
-    mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height();
+	mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height();
 
-    if (!node)
-    {
-        mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0;
-        mConsoleX = 0;  mConsoleY = 0;  mConsoleW = gr_fb_width();  mConsoleH = gr_fb_height();
-    }
-    else
-    {
-        child = node->first_node("font");
-        if (child)
-        {
-            attr = child->first_attribute("resource");
-            if (attr)
-                mFont = PageManager::FindResource(attr->value());
-        }
+	if (!node)
+	{
+		mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0;
+		mConsoleX = 0;  mConsoleY = 0;  mConsoleW = gr_fb_width();  mConsoleH = gr_fb_height();
+	}
+	else
+	{
+		child = node->first_node("font");
+		if (child)
+		{
+			attr = child->first_attribute("resource");
+			if (attr)
+				mFont = PageManager::FindResource(attr->value());
+		}
 
-        child = node->first_node("color");
-        if (child)
-        {
-            attr = child->first_attribute("foreground");
-            if (attr)
-            {
-                std::string color = attr->value();
-                ConvertStrToColor(color, &mForegroundColor);
-            }
-            attr = child->first_attribute("background");
-            if (attr)
-            {
-                std::string color = attr->value();
-                ConvertStrToColor(color, &mBackgroundColor);
-            }
-            attr = child->first_attribute("scroll");
-            if (attr)
-            {
-                std::string color = attr->value();
-                ConvertStrToColor(color, &mScrollColor);
-            }
-        }
+		child = node->first_node("color");
+		if (child)
+		{
+			attr = child->first_attribute("foreground");
+			if (attr)
+			{
+				std::string color = attr->value();
+				ConvertStrToColor(color, &mForegroundColor);
+			}
+			attr = child->first_attribute("background");
+			if (attr)
+			{
+				std::string color = attr->value();
+				ConvertStrToColor(color, &mBackgroundColor);
+			}
+			attr = child->first_attribute("scroll");
+			if (attr)
+			{
+				std::string color = attr->value();
+				ConvertStrToColor(color, &mScrollColor);
+			}
+		}
 
-        // Load the placement
-        LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
+		// Load the placement
+		LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
 
-        child = node->first_node("slideout");
-        if (child)
-        {
-            mSlideout = 1;
-            LoadPlacement(child, &mSlideoutX, &mSlideoutY);
+		child = node->first_node("slideout");
+		if (child)
+		{
+			mSlideout = 1;
+			LoadPlacement(child, &mSlideoutX, &mSlideoutY);
 
-            attr = child->first_attribute("resource");
-            if (attr)   mSlideoutImage = PageManager::FindResource(attr->value());
+			attr = child->first_attribute("resource");
+			if (attr)   mSlideoutImage = PageManager::FindResource(attr->value());
 
-            if (mSlideoutImage && mSlideoutImage->GetResource())
-            {
-                mSlideoutW = gr_get_width(mSlideoutImage->GetResource());
-                mSlideoutH = gr_get_height(mSlideoutImage->GetResource());
-            }
-        }
-    }
+			if (mSlideoutImage && mSlideoutImage->GetResource())
+			{
+				mSlideoutW = gr_get_width(mSlideoutImage->GetResource());
+				mSlideoutH = gr_get_height(mSlideoutImage->GetResource());
+			}
+		}
+	}
 
-    gr_getFontDetails(mFont, &mFontHeight, NULL);
-    SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
-    SetRenderPos(mConsoleX, mConsoleY);
-    return;
+	gr_getFontDetails(mFont, &mFontHeight, NULL);
+	SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
+	SetRenderPos(mConsoleX, mConsoleY);
+	return;
 }
 
 int GUIConsole::RenderSlideout(void)
 {
-    if (!mSlideoutImage || !mSlideoutImage->GetResource())      return -1;
+	if (!mSlideoutImage || !mSlideoutImage->GetResource())
+		return -1;
 
-    gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY);
-    return 0;
+	gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY);
+	return 0;
 }
 
 int GUIConsole::RenderConsole(void)
 {
-    void* fontResource = NULL;
-    if (mFont)  fontResource = mFont->GetResource();
+	void* fontResource = NULL;
+	if (mFont)
+		fontResource = mFont->GetResource();
 
-    // We fill the background
-    gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
-    gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH);
+	// We fill the background
+	gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
+	gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH);
 
-    gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha);
-    gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH);
+	gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha);
+	gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH);
 
-    // Render the lines
-    gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha);
+	// Render the lines
+	gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha);
 
-    // Don't try to continue to render without data
-    mLastCount = gConsole.size();
-    if (mLastCount == 0)        return (mSlideout ? RenderSlideout() : 0);
+	// Don't try to continue to render without data
+	mLastCount = gConsole.size();
+	if (mLastCount == 0)
+		return (mSlideout ? RenderSlideout() : 0);
 
-    // Find the start point
-    int start;
-    int curLine = mCurrentLine;    // Thread-safing (Another thread updates this value)
-    if (curLine == -1)
-    {
-        start = mLastCount - mMaxRows;
-    }
-    else
-    {
-        if (curLine > (int) mLastCount)   curLine = (int) mLastCount;
-        if ((int) mMaxRows > curLine)     curLine = (int) mMaxRows;
-        start = curLine - mMaxRows;
-    }
+	// Find the start point
+	int start;
+	int curLine = mCurrentLine; // Thread-safing (Another thread updates this value)
+	if (curLine == -1)
+	{
+		start = mLastCount - mMaxRows;
+	}
+	else
+	{
+		if (curLine > (int) mLastCount)
+			curLine = (int) mLastCount;
+		if ((int) mMaxRows > curLine)
+			curLine = (int) mMaxRows;
+		start = curLine - mMaxRows;
+	}
 
-    unsigned int line;
-    for (line = 0; line < mMaxRows; line++)
-    {
-        if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount)
-        {
-            gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX);
-        }
-    }
-    return (mSlideout ? RenderSlideout() : 0);
+	unsigned int line;
+	for (line = 0; line < mMaxRows; line++)
+	{
+		if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount)
+			gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX);
+	}
+	return (mSlideout ? RenderSlideout() : 0);
 }
 
 int GUIConsole::Render(void)
 {
-    if (mSlideout && mSlideoutState == hidden)
-    {
-        return RenderSlideout();
-    }
-    return RenderConsole();
+	if (mSlideout && mSlideoutState == hidden)
+		return RenderSlideout();
+
+	return RenderConsole();
 }
 
 int GUIConsole::Update(void)
 {
-    if (mSlideout && mSlideoutState != visible)
-    {
-        if (mSlideoutState == hidden)
-            return 0;
+	if (mSlideout && mSlideoutState != visible)
+	{
+		if (mSlideoutState == hidden)
+			return 0;
 
-        if (mSlideoutState == request_hide)
-            mSlideoutState = hidden;
+		if (mSlideoutState == request_hide)
+			mSlideoutState = hidden;
 
-        if (mSlideoutState == request_show)
-            mSlideoutState = visible;
+		if (mSlideoutState == request_show)
+			mSlideoutState = visible;
 
-        // Any time we activate the slider, we reset the position
-        mCurrentLine = -1;
-        return 2;
-    }
+		// Any time we activate the slider, we reset the position
+		mCurrentLine = -1;
+		return 2;
+	}
 
-    if (mCurrentLine == -1 && mLastCount != gConsole.size())
-    {
-        // We can use Render, and return for just a flip
-        Render();
-        return 2;
-    }
-    else if (mLastTouchY >= 0)
-    {
-        // They're still touching, so re-render
-        Render();
-        mLastTouchY = -1;
-        return 2;
-    }
-    return 0;
+	if (mCurrentLine == -1 && mLastCount != gConsole.size())
+	{
+		// We can use Render, and return for just a flip
+		Render();
+		return 2;
+	}
+	else if (mLastTouchY >= 0)
+	{
+		// They're still touching, so re-render
+		Render();
+		mLastTouchY = -1;
+		return 2;
+	}
+	return 0;
 }
 
 int GUIConsole::SetRenderPos(int x, int y, int w, int h)
 {
-    // Adjust the stub position accordingly
-    mSlideoutX += (x - mConsoleX);
-    mSlideoutY += (y - mConsoleY);
+	// Adjust the stub position accordingly
+	mSlideoutX += (x - mConsoleX);
+	mSlideoutY += (y - mConsoleY);
 
-    mConsoleX = x;
-    mConsoleY = y;
-    if (w || h)
-    {
-        mConsoleW = w;
-        mConsoleH = h;
-    }
+	mConsoleX = x;
+	mConsoleY = y;
+	if (w || h)
+	{
+		mConsoleW = w;
+		mConsoleH = h;
+	}
 
-    // Calculate the max rows
-    mMaxRows = mConsoleH / mFontHeight;
+	// Calculate the max rows
+	mMaxRows = mConsoleH / mFontHeight;
 
-    // Adjust so we always fit to bottom
-    mStartY = mConsoleY + (mConsoleH % mFontHeight);
-    return 0;
+	// Adjust so we always fit to bottom
+	mStartY = mConsoleY + (mConsoleH % mFontHeight);
+	return 0;
 }
 
 // IsInRegion - Checks if the request is handled by this object
 //  Return 0 if this object handles the request, 1 if not
 int GUIConsole::IsInRegion(int x, int y)
 {
-    if (mSlideout)
-    {
-        // Check if they tapped the slideout button
-        if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH)
-            return 1;
+	if (mSlideout)
+	{
+		// Check if they tapped the slideout button
+		if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH)
+			return 1;
 
-        // If we're only rendering the slideout, bail now
-        if (mSlideoutState == hidden)
-            return 0;
-    }
+		// If we're only rendering the slideout, bail now
+		if (mSlideoutState == hidden)
+			return 0;
+	}
 
-    return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1;
+	return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1;
 }
 
 // NotifyTouch - Notify of a touch event
 //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
 int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    if (mSlideout && mSlideoutState == hidden)
-    {
-        if (state == TOUCH_START)
-        {
-            mSlideoutState = request_show;
-            return 1;
-        }
-    }
-    else if (mSlideout && mSlideoutState == visible)
-    {
-        // Are we sliding it back in?
-        if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH))
-        {
-            mSlideoutState = request_hide;
-            return 1;
-        }
-    }
+	if (mSlideout && mSlideoutState == hidden)
+	{
+		if (state == TOUCH_START)
+		{
+			mSlideoutState = request_show;
+			return 1;
+		}
+	}
+	else if (mSlideout && mSlideoutState == visible)
+	{
+		// Are we sliding it back in?
+		if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH))
+		{
+			mSlideoutState = request_hide;
+			return 1;
+		}
+	}
 
-    // If we don't have enough lines to scroll, throw this away.
-    if (mLastCount < mMaxRows)   return 1;
+	// If we don't have enough lines to scroll, throw this away.
+	if (mLastCount < mMaxRows)   return 1;
 
-    // We are scrolling!!!
-    switch (state)
-    {
-    case TOUCH_START:
-        mLastTouchX = x;
-        mLastTouchY = y;
-        if ((x - mConsoleX) > ((9 * mConsoleW) / 10))
-            mSlideMultiplier = 10;
-        else
-            mSlideMultiplier = 1;
-        break;
+	// We are scrolling!!!
+	switch (state)
+	{
+	case TOUCH_START:
+		mLastTouchX = x;
+		mLastTouchY = y;
+		if ((x - mConsoleX) > ((9 * mConsoleW) / 10))
+			mSlideMultiplier = 10;
+		else
+			mSlideMultiplier = 1;
+		break;
 
-    case TOUCH_DRAG:
-        // This handles tapping
-        if (x == mLastTouchX && y == mLastTouchY)   break;
-        mLastTouchX = -1;
+	case TOUCH_DRAG:
+		// This handles tapping
+		if (x == mLastTouchX && y == mLastTouchY)   break;
+		mLastTouchX = -1;
 
-        if (y > mLastTouchY + 5)
-        {
-            mLastTouchY = y;
-            if (mCurrentLine == -1)
-                mCurrentLine = mLastCount - 1;
-            else if (mCurrentLine > mSlideMultiplier)
-                mCurrentLine -= mSlideMultiplier;
-            else
-                mCurrentLine = mMaxRows;
+		if (y > mLastTouchY + 5)
+		{
+			mLastTouchY = y;
+			if (mCurrentLine == -1)
+				mCurrentLine = mLastCount - 1;
+			else if (mCurrentLine > mSlideMultiplier)
+				mCurrentLine -= mSlideMultiplier;
+			else
+				mCurrentLine = mMaxRows;
 
-            if (mCurrentLine < (int) mMaxRows)
-                mCurrentLine = mMaxRows;
-        }
-        else if (y < mLastTouchY - 5)
-        {
-            mLastTouchY = y;
-            if (mCurrentLine >= 0)
-            {
-                mCurrentLine += mSlideMultiplier;
-                if (mCurrentLine >= (int) mLastCount)
-                    mCurrentLine = -1;
-            }
-        }
-        break;
+			if (mCurrentLine < (int) mMaxRows)
+				mCurrentLine = mMaxRows;
+		}
+		else if (y < mLastTouchY - 5)
+		{
+			mLastTouchY = y;
+			if (mCurrentLine >= 0)
+			{
+				mCurrentLine += mSlideMultiplier;
+				if (mCurrentLine >= (int) mLastCount)
+					mCurrentLine = -1;
+			}
+		}
+		break;
 
-    case TOUCH_RELEASE:
-        // On a tap, we jump to the tail
-        if (mLastTouchX >= 0)
-            mCurrentLine = -1;
+	case TOUCH_RELEASE:
+		// On a tap, we jump to the tail
+		if (mLastTouchX >= 0)
+			mCurrentLine = -1;
 
-        mLastTouchY = -1;
+		mLastTouchY = -1;
 	case TOUCH_REPEAT:
 	case TOUCH_HOLD:
-        break;
-    }
-    return 0;
+		break;
+	}
+	return 0;
 }
-
diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp
index 539bba0..0f8d903 100644
--- a/gui/fileselector.cpp
+++ b/gui/fileselector.cpp
@@ -198,12 +198,12 @@
 
 		attr = child->first_attribute("highlightcolor");
 		memset(&mFontHighlightColor, 0, sizeof(COLOR));
-        if (attr)
-        {
-            std::string color = attr->value();
+		if (attr)
+		{
+			std::string color = attr->value();
 			ConvertStrToColor(color, &mFontHighlightColor);
 			hasFontHighlightColor = true;
-        }
+		}
 	}
 
 	// Load the separator if it exists
@@ -408,11 +408,10 @@
 	if (updateFileList) {
 		string value;
 		DataManager::GetValue(mPathVar, value);
-		if (GetFileList(value) == 0) {
+		if (GetFileList(value) == 0)
 			updateFileList = false;
-		} else {
+		else
 			return 0;
-		}
 	}
 
 	// This tells us how many lines we can actually render
@@ -652,7 +651,9 @@
 int GUIFileSelector::GetSelection(int x, int y)
 {
 	// We only care about y position
-	if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) return -1;
+	if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH)
+		return -1;
+
 	return (y - mRenderY - mHeaderH);
 }
 
@@ -674,7 +675,6 @@
 		startY = lastY = last2Y = y;
 		scrollingSpeed = 0;
 		break;
-
 	case TOUCH_DRAG:
 		// Check if we dragged out of the selection window
 		if (GetSelection(x, y) == -1) {
diff --git a/gui/fill.cpp b/gui/fill.cpp
index 901eee1..ad1f4e0 100644
--- a/gui/fill.cpp
+++ b/gui/fill.cpp
@@ -27,31 +27,31 @@
 
 GUIFill::GUIFill(xml_node<>* node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    if (!node)
-        return;
+	if (!node)
+		return;
 
-    attr = node->first_attribute("color");
-    if (!attr) {
+	attr = node->first_attribute("color");
+	if (!attr) {
 		LOGERR("No color specified for fill\n");
-        return;
+		return;
 	}
 
-    std::string color = attr->value();
-    ConvertStrToColor(color, &mColor);
+	std::string color = attr->value();
+	ConvertStrToColor(color, &mColor);
 
-    // Load the placement
-    LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
+	// Load the placement
+	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
 
-    return;
+	return;
 }
 
 int GUIFill::Render(void)
 {
-    gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
-    gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
-    return 0;
+	gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
+	gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
+	return 0;
 }
 
diff --git a/gui/gui.cpp b/gui/gui.cpp
index 8755689..821c7f5 100644
--- a/gui/gui.cpp
+++ b/gui/gui.cpp
@@ -69,685 +69,659 @@
 
 static int gRecorder = -1;
 
-extern "C" void gr_write_frame_to_file (int fd);
+extern "C" void gr_write_frame_to_file(int fd);
 
-void
-flip (void)
+void flip(void)
 {
-  if (gRecorder != -1)
+	if (gRecorder != -1)
 	{
-	  timespec time;
-	  clock_gettime (CLOCK_MONOTONIC, &time);
-	  write (gRecorder, &time, sizeof (timespec));
-	  gr_write_frame_to_file (gRecorder);
+		timespec time;
+		clock_gettime(CLOCK_MONOTONIC, &time);
+		write(gRecorder, &time, sizeof(timespec));
+		gr_write_frame_to_file(gRecorder);
 	}
-  gr_flip ();
-  return;
+	gr_flip();
 }
 
-void
-rapidxml::parse_error_handler (const char *what, void *where)
+void rapidxml::parse_error_handler(const char *what, void *where)
 {
-  fprintf (stderr, "Parser error: %s\n", what);
-  fprintf (stderr, "  Start of string: %s\n", (char *) where);
-  LOGERR("Error parsing XML file.\n");
-  //abort ();
+	fprintf(stderr, "Parser error: %s\n", what);
+	fprintf(stderr, "  Start of string: %s\n",(char *) where);
+	LOGERR("Error parsing XML file.\n");
+	//abort();
 }
 
-static void
-curtainSet ()
+static void curtainSet()
 {
-  gr_color (0, 0, 0, 255);
-  gr_fill (0, 0, gr_fb_width (), gr_fb_height ());
-  gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), gr_get_height (gCurtain),
-		   0, 0);
-  gr_flip ();
-  return;
+	gr_color(0, 0, 0, 255);
+	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+	gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0);
+	gr_flip();
 }
 
-static void
-curtainRaise (gr_surface surface)
+static void curtainRaise(gr_surface surface)
 {
-  int sy = 0;
-  int h = gr_get_height (gCurtain) - 1;
-  int w = gr_get_width (gCurtain);
-  int fy = 1;
+	int sy = 0;
+	int h = gr_get_height(gCurtain) - 1;
+	int w = gr_get_width(gCurtain);
+	int fy = 1;
 
-  int msw = gr_get_width (surface);
-  int msh = gr_get_height (surface);
-  int CURTAIN_RATE = msh / 30;
+	int msw = gr_get_width(surface);
+	int msh = gr_get_height(surface);
+	int CURTAIN_RATE = msh / 30;
 
-  if (gNoAnimation == 0)
+	if (gNoAnimation == 0)
 	{
-	  for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE)
+		for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE)
 		{
-		  gr_blit (surface, 0, 0, msw, msh, 0, 0);
-		  gr_blit (gCurtain, 0, sy, w, h, 0, 0);
-		  gr_flip ();
+			gr_blit(surface, 0, 0, msw, msh, 0, 0);
+			gr_blit(gCurtain, 0, sy, w, h, 0, 0);
+			gr_flip();
 		}
 	}
-  gr_blit (surface, 0, 0, msw, msh, 0, 0);
-  flip ();
-  return;
+	gr_blit(surface, 0, 0, msw, msh, 0, 0);
+	flip();
 }
 
-void
-curtainClose ()
+void curtainClose()
 {
 #if 0
-  int w = gr_get_width (gCurtain);
-  int h = 1;
-  int sy = gr_get_height (gCurtain) - 1;
-  int fbh = gr_fb_height ();
-  int CURTAIN_RATE = fbh / 30;
+	int w = gr_get_width(gCurtain);
+	int h = 1;
+	int sy = gr_get_height(gCurtain) - 1;
+	int fbh = gr_fb_height();
+	int CURTAIN_RATE = fbh / 30;
 
-  if (gNoAnimation == 0)
+	if (gNoAnimation == 0)
 	{
-	  for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE)
+		for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE)
 		{
-		  gr_blit (gCurtain, 0, sy, w, h, 0, 0);
-		  gr_flip ();
+			gr_blit(gCurtain, 0, sy, w, h, 0, 0);
+			gr_flip();
 		}
-	  gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain),
-			   gr_get_height (gCurtain), 0, 0);
-	  gr_flip ();
+		gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain),
+		gr_get_height(gCurtain), 0, 0);
+		gr_flip();
 
-	  if (gRecorder != -1)
-		close (gRecorder);
+		if (gRecorder != -1)
+			close(gRecorder);
 
-	  int fade;
-	  for (fade = 16; fade < 255; fade += CURTAIN_FADE)
+		int fade;
+		for (fade = 16; fade < 255; fade += CURTAIN_FADE)
 		{
-		  gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain),
-				   gr_get_height (gCurtain), 0, 0);
-		  gr_color (0, 0, 0, fade);
-		  gr_fill (0, 0, gr_fb_width (), gr_fb_height ());
-		  gr_flip ();
+			gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain),
+			gr_get_height(gCurtain), 0, 0);
+			gr_color(0, 0, 0, fade);
+			gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+			gr_flip();
 		}
-	  gr_color (0, 0, 0, 255);
-	  gr_fill (0, 0, gr_fb_width (), gr_fb_height ());
-	  gr_flip ();
+		gr_color(0, 0, 0, 255);
+		gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+		gr_flip();
 	}
 #else
-  gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), gr_get_height (gCurtain),
-		   0, 0);
-  gr_flip ();
+	gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0);
+	gr_flip();
 #endif
-  return;
 }
 
-static void *
-input_thread (void *cookie)
+static void * input_thread(void *cookie)
 {
-  int drag = 0;
-  static int touch_and_hold = 0, dontwait = 0, touch_repeat = 0, x = 0, y =
-	0, lshift = 0, rshift = 0, key_repeat = 0;
-  static struct timeval touchStart;
-  HardwareKeyboard kb;
-  string seconds;
+	int drag = 0;
+	static int touch_and_hold = 0, dontwait = 0;
+	static int touch_repeat = 0, key_repeat = 0;
+	static int x = 0, y = 0;
+	static int lshift = 0, rshift = 0;
+	static struct timeval touchStart;
+	HardwareKeyboard kb;
+	string seconds;
 
-  //start screen timeout threads
-  blankTimer.setTimerThread();
-  DataManager::GetValue("tw_screen_timeout_secs", seconds);
-  blankTimer.setTime(atoi(seconds.c_str()));
+	//start screen timeout threads
+	blankTimer.setTimerThread();
+	DataManager::GetValue("tw_screen_timeout_secs", seconds);
+	blankTimer.setTime(atoi(seconds.c_str()));
 
-  for (;;)
+	for (;;)
 	{
+		// wait for the next event
+		struct input_event ev;
+		int state = 0, ret = 0;
 
-	  // wait for the next event
-	  struct input_event ev;
-	  int state = 0, ret = 0;
+		ret = ev_get(&ev, dontwait);
 
-	  ret = ev_get (&ev, dontwait);
-
-	  if (ret < 0)
+		if (ret < 0)
 		{
-		  struct timeval curTime;
-		  gettimeofday (&curTime, NULL);
-		  long mtime, seconds, useconds;
+			struct timeval curTime;
+			gettimeofday(&curTime, NULL);
+			long mtime, seconds, useconds;
 
-		  seconds = curTime.tv_sec - touchStart.tv_sec;
-		  useconds = curTime.tv_usec - touchStart.tv_usec;
+			seconds = curTime.tv_sec - touchStart.tv_sec;
+			useconds = curTime.tv_usec - touchStart.tv_usec;
 
-		  mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
-		  if (touch_and_hold && mtime > 500)
+			mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
+			if (touch_and_hold && mtime > 500)
 			{
-			  touch_and_hold = 0;
-			  touch_repeat = 1;
-			  gettimeofday (&touchStart, NULL);
+				touch_and_hold = 0;
+				touch_repeat = 1;
+				gettimeofday(&touchStart, NULL);
 #ifdef _EVENT_LOGGING
-			  LOGERR("TOUCH_HOLD: %d,%d\n", x, y);
+				LOGERR("TOUCH_HOLD: %d,%d\n", x, y);
 #endif
-			  PageManager::NotifyTouch (TOUCH_HOLD, x, y);
-                          blankTimer.resetTimerAndUnblank();
+				PageManager::NotifyTouch(TOUCH_HOLD, x, y);
+				blankTimer.resetTimerAndUnblank();
 			}
-		  else if (touch_repeat && mtime > 100)
+			else if (touch_repeat && mtime > 100)
 			{
 #ifdef _EVENT_LOGGING
-			  LOGERR("TOUCH_REPEAT: %d,%d\n", x, y);
+				LOGERR("TOUCH_REPEAT: %d,%d\n", x, y);
 #endif
-			  gettimeofday (&touchStart, NULL);
-			  PageManager::NotifyTouch (TOUCH_REPEAT, x, y);
-                          blankTimer.resetTimerAndUnblank();
+				gettimeofday(&touchStart, NULL);
+				PageManager::NotifyTouch(TOUCH_REPEAT, x, y);
+				blankTimer.resetTimerAndUnblank();
 			}
-		  else if (key_repeat == 1 && mtime > 500)
+			else if (key_repeat == 1 && mtime > 500)
 			{
 #ifdef _EVENT_LOGGING
-			  LOGERR("KEY_HOLD: %d,%d\n", x, y);
+				LOGERR("KEY_HOLD: %d,%d\n", x, y);
 #endif
-			  gettimeofday (&touchStart, NULL);
-			  key_repeat = 2;
-			  kb.KeyRepeat ();
-                          blankTimer.resetTimerAndUnblank();
+				gettimeofday(&touchStart, NULL);
+				key_repeat = 2;
+				kb.KeyRepeat();
+				blankTimer.resetTimerAndUnblank();
 			}
-		  else if (key_repeat == 2 && mtime > 100)
+			else if (key_repeat == 2 && mtime > 100)
 			{
 #ifdef _EVENT_LOGGING
-			  LOGERR("KEY_REPEAT: %d,%d\n", x, y);
+				LOGERR("KEY_REPEAT: %d,%d\n", x, y);
 #endif
-			  gettimeofday (&touchStart, NULL);
-			  kb.KeyRepeat ();
-                          blankTimer.resetTimerAndUnblank();
+				gettimeofday(&touchStart, NULL);
+				kb.KeyRepeat();
+				blankTimer.resetTimerAndUnblank();
 			}
 		}
-	  else if (ev.type == EV_ABS)
+		else if (ev.type == EV_ABS)
 		{
 
-		  x = ev.value >> 16;
-		  y = ev.value & 0xFFFF;
+			x = ev.value >> 16;
+			y = ev.value & 0xFFFF;
 
-		  if (ev.code == 0)
+			if (ev.code == 0)
 			{
-			  if (state == 0)
+				if (state == 0)
 				{
 #ifdef _EVENT_LOGGING
-				  LOGERR("TOUCH_RELEASE: %d,%d\n", x, y);
+					LOGERR("TOUCH_RELEASE: %d,%d\n", x, y);
 #endif
-				  PageManager::NotifyTouch (TOUCH_RELEASE, x, y);
-				  blankTimer.resetTimerAndUnblank();
-				  touch_and_hold = 0;
-				  touch_repeat = 0;
-				  if (!key_repeat)
-					dontwait = 0;
+					PageManager::NotifyTouch(TOUCH_RELEASE, x, y);
+					blankTimer.resetTimerAndUnblank();
+					touch_and_hold = 0;
+					touch_repeat = 0;
+					if (!key_repeat)
+						dontwait = 0;
 				}
-			  state = 0;
-			  drag = 0;
+				state = 0;
+				drag = 0;
 			}
-		  else
+			else
 			{
-			  if (!drag)
+				if (!drag)
 				{
 #ifdef _EVENT_LOGGING
-				  LOGERR("TOUCH_START: %d,%d\n", x, y);
+					LOGERR("TOUCH_START: %d,%d\n", x, y);
 #endif
-				  if (PageManager::NotifyTouch (TOUCH_START, x, y) > 0)
-					state = 1;
-				  drag = 1;
-				  touch_and_hold = 1;
-				  dontwait = 1;
-				  key_repeat = 0;
-				  gettimeofday (&touchStart, NULL);
-				  blankTimer.resetTimerAndUnblank();
+					if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0)
+						state = 1;
+					drag = 1;
+					touch_and_hold = 1;
+					dontwait = 1;
+					key_repeat = 0;
+					gettimeofday(&touchStart, NULL);
+					blankTimer.resetTimerAndUnblank();
 				}
-			  else
+				else
 				{
-				  if (state == 0)
+					if (state == 0)
 					{
 #ifdef _EVENT_LOGGING
-					  LOGERR("TOUCH_DRAG: %d,%d\n", x, y);
+						LOGERR("TOUCH_DRAG: %d,%d\n", x, y);
 #endif
-					  if (PageManager::NotifyTouch (TOUCH_DRAG, x, y) > 0)
-						state = 1;
-					  key_repeat = 0;
-					  blankTimer.resetTimerAndUnblank();
+						if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0)
+							state = 1;
+						key_repeat = 0;
+						blankTimer.resetTimerAndUnblank();
 					}
 				}
 			}
 		}
-	  else if (ev.type == EV_KEY)
+		else if (ev.type == EV_KEY)
 		{
-		  // Handle key-press here
+			// Handle key-press here
 #ifdef _EVENT_LOGGING
-		  LOGERR("TOUCH_KEY: %d\n", ev.code);
+			LOGERR("TOUCH_KEY: %d\n", ev.code);
 #endif
-		  if (ev.value != 0)
+			if (ev.value != 0)
 			{
-			  // This is a key press
-			  if (kb.KeyDown (ev.code))
+				// This is a key press
+				if (kb.KeyDown(ev.code))
 				{
-				  key_repeat = 1;
-				  touch_and_hold = 0;
-				  touch_repeat = 0;
-				  dontwait = 1;
-				  gettimeofday (&touchStart, NULL);
-				  blankTimer.resetTimerAndUnblank();
+					key_repeat = 1;
+					touch_and_hold = 0;
+					touch_repeat = 0;
+					dontwait = 1;
+					gettimeofday(&touchStart, NULL);
+					blankTimer.resetTimerAndUnblank();
 				}
-			  else
+				else
 				{
-				  key_repeat = 0;
-				  touch_and_hold = 0;
-				  touch_repeat = 0;
-				  dontwait = 0;
-				  blankTimer.resetTimerAndUnblank();
+					key_repeat = 0;
+					touch_and_hold = 0;
+					touch_repeat = 0;
+					dontwait = 0;
+					blankTimer.resetTimerAndUnblank();
 				}
 			}
-		  else
+			else
 			{
-			  // This is a key release
-			  kb.KeyUp (ev.code);
-			  key_repeat = 0;
-			  touch_and_hold = 0;
-			  touch_repeat = 0;
-			  dontwait = 0;
-                          blankTimer.resetTimerAndUnblank();
+				// This is a key release
+				kb.KeyUp(ev.code);
+				key_repeat = 0;
+				touch_and_hold = 0;
+				touch_repeat = 0;
+				dontwait = 0;
+				blankTimer.resetTimerAndUnblank();
 			}
 		}
 	}
-  return NULL;
+	return NULL;
 }
 
 // This special function will return immediately the first time, but then
 // always returns 1/30th of a second (or immediately if called later) from
 // the last time it was called
-static void
-loopTimer (void)
+static void loopTimer(void)
 {
-  static timespec lastCall;
-  static int initialized = 0;
+	static timespec lastCall;
+	static int initialized = 0;
 
-  if (!initialized)
+	if (!initialized)
 	{
-	  clock_gettime (CLOCK_MONOTONIC, &lastCall);
-	  initialized = 1;
-	  return;
+		clock_gettime(CLOCK_MONOTONIC, &lastCall);
+		initialized = 1;
+		return;
 	}
 
-  do
+	do
 	{
-	  timespec curTime;
-	  clock_gettime (CLOCK_MONOTONIC, &curTime);
+		timespec curTime;
+		clock_gettime(CLOCK_MONOTONIC, &curTime);
 
-	  timespec diff = TWFunc::timespec_diff (lastCall, curTime);
+		timespec diff = TWFunc::timespec_diff(lastCall, curTime);
 
-	  // This is really 30 times per second
-	  if (diff.tv_sec || diff.tv_nsec > 33333333)
+		// This is really 30 times per second
+		if (diff.tv_sec || diff.tv_nsec > 33333333)
 		{
-		  lastCall = curTime;
-		  return;
+			lastCall = curTime;
+			return;
 		}
 
-	  // We need to sleep some period time microseconds
-	  unsigned int sleepTime = 33333 - (diff.tv_nsec / 1000);
-	  usleep (sleepTime);
-	}
-  while (1);
-  return;
+		// We need to sleep some period time microseconds
+		unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000);
+		usleep(sleepTime);
+	} while (1);
 }
 
-static int
-runPages (void)
+static int runPages(void)
 {
-  // Raise the curtain
-  if (gCurtain != NULL)
+	// Raise the curtain
+	if (gCurtain != NULL)
 	{
-	  gr_surface surface;
+		gr_surface surface;
 
-	  PageManager::Render ();
-	  gr_get_surface (&surface);
-	  curtainRaise (surface);
-	  gr_free_surface (surface);
+		PageManager::Render();
+		gr_get_surface(&surface);
+		curtainRaise(surface);
+		gr_free_surface(surface);
 	}
 
-  gGuiRunning = 1;
+	gGuiRunning = 1;
 
-  DataManager::SetValue ("tw_loaded", 1);
+	DataManager::SetValue("tw_loaded", 1);
 
-  for (;;)
+	for (;;)
 	{
-	  loopTimer ();
+		loopTimer();
 
-	  if (!gForceRender)
+		if (!gForceRender)
 		{
-		  int ret;
+			int ret;
 
-		  ret = PageManager::Update ();
-		  if (ret > 1)
-			PageManager::Render ();
+			ret = PageManager::Update();
+			if (ret > 1)
+				PageManager::Render();
 
-		  if (ret > 0)
-			flip ();
+			if (ret > 0)
+				flip();
 		}
-	  else
+		else
 		{
-		  pthread_mutex_lock(&gForceRendermutex);
-		  gForceRender = 0;
-		  pthread_mutex_unlock(&gForceRendermutex);
-		  PageManager::Render ();
-		  flip ();
+			pthread_mutex_lock(&gForceRendermutex);
+			gForceRender = 0;
+			pthread_mutex_unlock(&gForceRendermutex);
+			PageManager::Render();
+			flip();
 		}
+
 		if (DataManager::GetIntValue("tw_gui_done") != 0)
+			break;
+	}
+
+	gGuiRunning = 0;
+	return 0;
+}
+
+static int runPage(const char *page_name)
+{
+	gui_changePage(page_name);
+
+	// Raise the curtain
+	if (gCurtain != NULL)
+	{
+		gr_surface surface;
+
+		PageManager::Render();
+		gr_get_surface(&surface);
+		curtainRaise(surface);
+		gr_free_surface(surface);
+	}
+
+	gGuiRunning = 1;
+
+	DataManager::SetValue("tw_loaded", 1);
+
+	for (;;)
+	{
+		loopTimer();
+
+		if (!gForceRender)
 		{
+			int ret;
+
+			ret = PageManager::Update();
+			if (ret > 1)
+				PageManager::Render();
+
+			if (ret > 0)
+				flip();
+		}
+		else
+		{
+			pthread_mutex_lock(&gForceRendermutex);
+			gForceRender = 0;
+			pthread_mutex_unlock(&gForceRendermutex);
+			PageManager::Render();
+			flip();
+		}
+		if (DataManager::GetIntValue("tw_page_done") != 0)
+		{
+			gui_changePage("main");
 			break;
 		}
 	}
 
-  gGuiRunning = 0;
-  return 0;
+	gGuiRunning = 0;
+	return 0;
 }
 
-static int
-runPage (const char *page_name)
+int gui_forceRender(void)
 {
-  gui_changePage (page_name);
+	pthread_mutex_lock(&gForceRendermutex);
+	gForceRender = 1;
+	pthread_mutex_unlock(&gForceRendermutex);
+	return 0;
+}
 
-  // Raise the curtain
-  if (gCurtain != NULL)
+int gui_changePage(std::string newPage)
+{
+	LOGINFO("Set page: '%s'\n", newPage.c_str());
+	PageManager::ChangePage(newPage);
+	pthread_mutex_lock(&gForceRendermutex);
+	gForceRender = 1;
+	pthread_mutex_unlock(&gForceRendermutex);
+	return 0;
+}
+
+int gui_changeOverlay(std::string overlay)
+{
+	PageManager::ChangeOverlay(overlay);
+	pthread_mutex_lock(&gForceRendermutex);
+	gForceRender = 1;
+	pthread_mutex_unlock(&gForceRendermutex);
+	return 0;
+}
+
+int gui_changePackage(std::string newPackage)
+{
+	PageManager::SelectPackage(newPackage);
+	pthread_mutex_lock(&gForceRendermutex);
+	gForceRender = 1;
+	pthread_mutex_unlock(&gForceRendermutex);
+	return 0;
+}
+
+std::string gui_parse_text(string inText)
+{
+	// Copied from std::string GUIText::parseText(void)
+	// This function parses text for DataManager values encompassed by %value% in the XML
+	static int counter = 0;
+	std::string str = inText;
+	size_t pos = 0;
+	size_t next = 0, end = 0;
+
+	while (1)
 	{
-	  gr_surface surface;
+		next = str.find('%', pos);
+		if (next == std::string::npos)
+			return str;
 
-	  PageManager::Render ();
-	  gr_get_surface (&surface);
-	  curtainRaise (surface);
-	  gr_free_surface (surface);
-	}
+		end = str.find('%', next + 1);
+		if (end == std::string::npos)
+			return str;
 
-  gGuiRunning = 1;
+		// We have a block of data
+		std::string var = str.substr(next + 1,(end - next) - 1);
+		str.erase(next,(end - next) + 1);
 
-  DataManager::SetValue ("tw_loaded", 1);
-
-  for (;;)
-	{
-	  loopTimer ();
-
-	  if (!gForceRender)
+		if (next + 1 == end)
+			str.insert(next, 1, '%');
+		else
 		{
-		  int ret;
-
-		  ret = PageManager::Update ();
-		  if (ret > 1)
-			PageManager::Render ();
-
-		  if (ret > 0)
-			flip ();
-		}
-	  else
-		{
-		  pthread_mutex_lock(&gForceRendermutex);
-		  gForceRender = 0;
-		  pthread_mutex_unlock(&gForceRendermutex);
-		  PageManager::Render ();
-		  flip ();
-		}
-	  if (DataManager::GetIntValue ("tw_page_done") != 0)
-		{
-		  gui_changePage ("main");
-		  break;
-		}
-	}
-
-  gGuiRunning = 0;
-  return 0;
-}
-
-int
-gui_forceRender (void)
-{
-  pthread_mutex_lock(&gForceRendermutex);
-  gForceRender = 1;
-  pthread_mutex_unlock(&gForceRendermutex);
-  return 0;
-}
-
-int
-gui_changePage (std::string newPage)
-{
-  LOGINFO("Set page: '%s'\n", newPage.c_str ());
-  PageManager::ChangePage (newPage);
-  pthread_mutex_lock(&gForceRendermutex);
-  gForceRender = 1;
-  pthread_mutex_unlock(&gForceRendermutex);
-  return 0;
-}
-
-int
-gui_changeOverlay (std::string overlay)
-{
-  PageManager::ChangeOverlay (overlay);
-  pthread_mutex_lock(&gForceRendermutex);
-  gForceRender = 1;
-  pthread_mutex_unlock(&gForceRendermutex);
-  return 0;
-}
-
-int
-gui_changePackage (std::string newPackage)
-{
-  PageManager::SelectPackage (newPackage);
-  pthread_mutex_lock(&gForceRendermutex);
-  gForceRender = 1;
-  pthread_mutex_unlock(&gForceRendermutex);
-  return 0;
-}
-
-std::string gui_parse_text (string inText)
-{
-  // Copied from std::string GUIText::parseText(void)
-  // This function parses text for DataManager values encompassed by %value% in the XML
-  static int counter = 0;
-  std::string str = inText;
-  size_t pos = 0;
-  size_t next = 0, end = 0;
-
-  while (1)
-	{
-	  next = str.find ('%', pos);
-	  if (next == std::string::npos)
-		return str;
-	  end = str.find ('%', next + 1);
-	  if (end == std::string::npos)
-		return str;
-
-	  // We have a block of data
-	  std::string var = str.substr (next + 1, (end - next) - 1);
-	  str.erase (next, (end - next) + 1);
-
-	  if (next + 1 == end)
-		{
-		  str.insert (next, 1, '%');
-		}
-	  else
-		{
-		  std::string value;
-		  if (DataManager::GetValue (var, value) == 0)
-			str.insert (next, value);
+			std::string value;
+			if (DataManager::GetValue(var, value) == 0)
+				str.insert(next, value);
 		}
 
-	  pos = next + 1;
+		pos = next + 1;
 	}
 }
 
-extern "C" int
-gui_init ()
+extern "C" int gui_init(void)
 {
-  int fd;
+	int fd;
 
-  gr_init ();
+	gr_init();
 
-  if (res_create_surface ("/res/images/curtain.jpg", &gCurtain))
+	if (res_create_surface("/res/images/curtain.jpg", &gCurtain))
 	{
-	  printf
+		printf
 		("Unable to locate '/res/images/curtain.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n");
-	  return -1;
+		return -1;
 	}
 
-  curtainSet ();
+	curtainSet();
 
-  ev_init ();
-  return 0;
+	ev_init();
+	return 0;
 }
 
-extern "C" int
-gui_loadResources ()
+extern "C" int gui_loadResources(void)
 {
-//    unlink("/sdcard/video.last");
-//    rename("/sdcard/video.bin", "/sdcard/video.last");
-//    gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY);
+	//    unlink("/sdcard/video.last");
+	//    rename("/sdcard/video.bin", "/sdcard/video.last");
+	//    gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY);
 
-  int check = 0;
-  DataManager::GetValue (TW_IS_ENCRYPTED, check);
-  if (check)
+	int check = 0;
+	DataManager::GetValue(TW_IS_ENCRYPTED, check);
+	if (check)
 	{
-	  if (PageManager::LoadPackage ("TWRP", "/res/ui.xml", "decrypt"))
+		if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "decrypt"))
 		{
-		  LOGERR("Failed to load base packages.\n");
-		  goto error;
+			LOGERR("Failed to load base packages.\n");
+			goto error;
 		}
-	  else
-		check = 1;
+		else
+			check = 1;
 	}
-  if (check == 0
-	  && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main"))
-	{
-	  std::string theme_path;
 
-	  theme_path = DataManager::GetSettingsStoragePath ();
-	  if (!PartitionManager.Mount_Settings_Storage(false))
+	if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main"))
+	{
+		std::string theme_path;
+
+		theme_path = DataManager::GetSettingsStoragePath();
+		if (!PartitionManager.Mount_Settings_Storage(false))
 		{
-		  int retry_count = 5;
-		  while (retry_count > 0
-				 && !PartitionManager.Mount_Settings_Storage(false))
+			int retry_count = 5;
+			while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false))
 			{
-			  usleep (500000);
-			  retry_count--;
+				usleep(500000);
+				retry_count--;
 			}
-		  if (!PartitionManager.Mount_Settings_Storage(false))
+
+			if (!PartitionManager.Mount_Settings_Storage(false))
 			{
-			  LOGERR("Unable to mount %s during GUI startup.\n",
-					theme_path.c_str ());
-			  check = 1;
+				LOGERR("Unable to mount %s during GUI startup.\n",
+					   theme_path.c_str());
+				check = 1;
 			}
 		}
 
-	  theme_path += "/TWRP/theme/ui.zip";
-	  if (check || PageManager::LoadPackage("TWRP", theme_path, "main"))
+		theme_path += "/TWRP/theme/ui.zip";
+		if (check || PageManager::LoadPackage("TWRP", theme_path, "main"))
 		{
-		  if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main"))
+			if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main"))
 			{
-			  LOGERR("Failed to load base packages.\n");
-			  goto error;
+				LOGERR("Failed to load base packages.\n");
+				goto error;
 			}
 		}
 	}
 
-  // Set the default package
-  PageManager::SelectPackage ("TWRP");
+	// Set the default package
+	PageManager::SelectPackage("TWRP");
 
-  gGuiInitialized = 1;
-  return 0;
+	gGuiInitialized = 1;
+	return 0;
 
 error:
-  LOGERR("An internal error has occurred.\n");
-  gGuiInitialized = 0;
-  return -1;
+	LOGERR("An internal error has occurred.\n");
+	gGuiInitialized = 0;
+	return -1;
 }
 
-extern "C" int
-gui_start ()
+extern "C" int gui_start(void)
 {
-  if (!gGuiInitialized)
-	return -1;
+	if (!gGuiInitialized)
+		return -1;
 
-  gGuiConsoleTerminate = 1;
-  while (gGuiConsoleRunning)
-	loopTimer ();
+	gGuiConsoleTerminate = 1;
 
-  // Set the default package
-  PageManager::SelectPackage ("TWRP");
+	while (gGuiConsoleRunning)
+		loopTimer();
 
-  if (!gGuiInputRunning)
+	// Set the default package
+	PageManager::SelectPackage("TWRP");
+
+	if (!gGuiInputRunning)
 	{
-	  // Start by spinning off an input handler.
-	  pthread_t t;
-	  pthread_create (&t, NULL, input_thread, NULL);
-	  gGuiInputRunning = 1;
+		// Start by spinning off an input handler.
+		pthread_t t;
+		pthread_create(&t, NULL, input_thread, NULL);
+		gGuiInputRunning = 1;
 	}
 
-  return runPages ();
+	return runPages();
 }
 
-extern "C" int
-gui_startPage (const char *page_name)
+extern "C" int gui_startPage(const char *page_name)
 {
-  if (!gGuiInitialized)
-	return -1;
+	if (!gGuiInitialized)
+		return -1;
 
-  gGuiConsoleTerminate = 1;
-  while (gGuiConsoleRunning)
-	loopTimer ();
+	gGuiConsoleTerminate = 1;
 
-  // Set the default package
-  PageManager::SelectPackage("TWRP");
+	while (gGuiConsoleRunning)
+		loopTimer();
 
-  if (!gGuiInputRunning)
+	// Set the default package
+	PageManager::SelectPackage("TWRP");
+
+	if (!gGuiInputRunning)
 	{
-	  // Start by spinning off an input handler.
-	  pthread_t t;
-	  pthread_create (&t, NULL, input_thread, NULL);
-	  gGuiInputRunning = 1;
+		// Start by spinning off an input handler.
+		pthread_t t;
+		pthread_create(&t, NULL, input_thread, NULL);
+		gGuiInputRunning = 1;
 	}
 
-  DataManager::SetValue("tw_page_done", 0);
-  return runPage (page_name);
+	DataManager::SetValue("tw_page_done", 0);
+	return runPage(page_name);
 }
 
-static void *
-console_thread (void *cookie)
+static void * console_thread(void *cookie)
 {
-  PageManager::SwitchToConsole ();
+	PageManager::SwitchToConsole();
 
-  while (!gGuiConsoleTerminate)
+	while (!gGuiConsoleTerminate)
 	{
-	  loopTimer ();
+		loopTimer();
 
-	  if (!gForceRender)
+		if (!gForceRender)
 		{
-		  int ret;
+			int ret;
 
-		  ret = PageManager::Update ();
-		  if (ret > 1)
-			PageManager::Render ();
+			ret = PageManager::Update();
+			if (ret > 1)
+				PageManager::Render();
 
-		  if (ret > 0)
-			flip ();
+			if (ret > 0)
+				flip();
 
-		  if (ret < 0)
-			LOGERR("An update request has failed.\n");
+			if (ret < 0)
+				LOGERR("An update request has failed.\n");
 		}
-	  else
+		else
 		{
-		  pthread_mutex_lock(&gForceRendermutex);
-		  gForceRender = 0;
-		  pthread_mutex_unlock(&gForceRendermutex);
-		  PageManager::Render ();
-		  flip ();
+			pthread_mutex_lock(&gForceRendermutex);
+			gForceRender = 0;
+			pthread_mutex_unlock(&gForceRendermutex);
+			PageManager::Render();
+			flip();
 		}
 	}
-  gGuiConsoleRunning = 0;
-  return NULL;
+	gGuiConsoleRunning = 0;
+	return NULL;
 }
 
-extern "C" int
-gui_console_only ()
+extern "C" int gui_console_only(void)
 {
-  if (!gGuiInitialized)
-	return -1;
+	if (!gGuiInitialized)
+		return -1;
 
-  gGuiConsoleTerminate = 0;
-  gGuiConsoleRunning = 1;
+	gGuiConsoleTerminate = 0;
+	gGuiConsoleRunning = 1;
 
-  // Start by spinning off an input handler.
-  pthread_t t;
-  pthread_create (&t, NULL, console_thread, NULL);
+	// Start by spinning off an input handler.
+	pthread_t t;
+	pthread_create(&t, NULL, console_thread, NULL);
 
-  return 0;
+	return 0;
 }
diff --git a/gui/hardwarekeyboard.cpp b/gui/hardwarekeyboard.cpp
index 96958d5..a5a9987 100644
--- a/gui/hardwarekeyboard.cpp
+++ b/gui/hardwarekeyboard.cpp
@@ -26,15 +26,18 @@
 #include "rapidxml.hpp"
 #include "objects.hpp"
 
-HardwareKeyboard::HardwareKeyboard(void) {
-	// Do Nothing
+HardwareKeyboard::HardwareKeyboard(void)
+{
+
 }
 
-HardwareKeyboard::~HardwareKeyboard() {
-	// Do Nothing
+HardwareKeyboard::~HardwareKeyboard()
+{
+	
 }
 
-int HardwareKeyboard::KeyDown(int key_code) {
+int HardwareKeyboard::KeyDown(int key_code)
+{
 #ifdef _EVENT_LOGGING
 	LOGERR("HardwareKeyboard::KeyDown %i\n", key_code);
 #endif
@@ -42,14 +45,16 @@
 	return 0; // 0 = no key repeat anything else turns on key repeat
 }
 
-int HardwareKeyboard::KeyUp(int key_code) {
+int HardwareKeyboard::KeyUp(int key_code)
+{
 #ifdef _EVENT_LOGGING
 	LOGERR("HardwareKeyboard::KeyUp %i\n", key_code);
 #endif
 	return 0;
 }
 
-int HardwareKeyboard::KeyRepeat(void) {
+int HardwareKeyboard::KeyRepeat(void)
+{
 #ifdef _EVENT_LOGGING
 	LOGERR("HardwareKeyboard::KeyRepeat\n");
 #endif
diff --git a/gui/image.cpp b/gui/image.cpp
index c684d1b..45d8636 100644
--- a/gui/image.cpp
+++ b/gui/image.cpp
@@ -27,71 +27,76 @@
 
 GUIImage::GUIImage(xml_node<>* node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mImage = NULL;
+	mImage = NULL;
 	mHighlightImage = NULL;
 	isHighlighted = false;
 
-    if (!node)
-        return;
+	if (!node)
+		return;
 
-    child = node->first_node("image");
-    if (child)
-    {
-        attr = child->first_attribute("resource");
-        if (attr)
-            mImage = PageManager::FindResource(attr->value());
+	child = node->first_node("image");
+	if (child)
+	{
+		attr = child->first_attribute("resource");
+		if (attr)
+			mImage = PageManager::FindResource(attr->value());
 		attr = child->first_attribute("highlightresource");
-        if (attr)
-            mHighlightImage = PageManager::FindResource(attr->value());
-    }
+		if (attr)
+			mHighlightImage = PageManager::FindResource(attr->value());
+	}
 
-    // Load the placement
-    LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
+	// Load the placement
+	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
 
-    if (mImage && mImage->GetResource())
-    {
-        mRenderW = gr_get_width(mImage->GetResource());
-        mRenderH = gr_get_height(mImage->GetResource());
+	if (mImage && mImage->GetResource())
+	{
+		mRenderW = gr_get_width(mImage->GetResource());
+		mRenderH = gr_get_height(mImage->GetResource());
 
-        // Adjust for placement
-        if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
-        {
-            if (mPlacement == CENTER)
-                mRenderX -= (mRenderW / 2);
-            else
-                mRenderX -= mRenderW;
-        }
-        if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
-        {
-            if (mPlacement == CENTER)
-                mRenderY -= (mRenderH / 2);
-            else
-                mRenderY -= mRenderH;
-        }
-        SetPlacement(TOP_LEFT);
-    }
+		// Adjust for placement
+		if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
+		{
+			if (mPlacement == CENTER)
+				mRenderX -= (mRenderW / 2);
+			else
+				mRenderX -= mRenderW;
+		}
+		if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
+		{
+			if (mPlacement == CENTER)
+				mRenderY -= (mRenderH / 2);
+			else
+				mRenderY -= mRenderH;
+		}
+		SetPlacement(TOP_LEFT);
+	}
 
-    return;
+	return;
 }
 
 int GUIImage::Render(void)
 {
-    if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
+	if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
 		gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
 		return 0;
-	} else if (!mImage || !mImage->GetResource())      return -1;
-    gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
-    return 0;
+	}
+	else if (!mImage || !mImage->GetResource())
+		return -1;
+
+	gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+	return 0;
 }
 
 int GUIImage::SetRenderPos(int x, int y, int w, int h)
 {
-    if (w || h)     return -1;
-    mRenderX = x;
-    mRenderY = y;
-    return 0;
+	if (w || h)
+		return -1;
+
+	mRenderX = x;
+	mRenderY = y;
+	return 0;
 }
 
diff --git a/gui/input.cpp b/gui/input.cpp
index e016724..19e4e6a 100644
--- a/gui/input.cpp
+++ b/gui/input.cpp
@@ -29,17 +29,17 @@
 #include "../data.hpp"
 
 GUIInput::GUIInput(xml_node<>* node)
-    : Conditional(node)
+	: Conditional(node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mInputText = NULL;
+	mInputText = NULL;
 	mAction = NULL;
 	mBackground = NULL;
 	mCursor = NULL;
 	mFont = NULL;
-    mRendered = false;
+	mRendered = false;
 	HasMask = false;
 	DrawCursor = false;
 	isLocalChange = true;
@@ -52,18 +52,19 @@
 	ConvertStrToColor("black", &mBackgroundColor);
 	ConvertStrToColor("white", &mCursorColor);
 
-    if (!node)  return;
+	if (!node)
+		return;
 
-    // Load text directly from the node
-    mInputText = new GUIText(node);
+	// Load text directly from the node
+	mInputText = new GUIText(node);
 	// Load action directly from the node
 	mAction = new GUIAction(node);
 
 	if (mInputText->Render() < 0)
-    {
-        delete mInputText;
-        mInputText = NULL;
-    }
+	{
+		delete mInputText;
+		mInputText = NULL;
+	}
 
 	// Load the background
 	child = node->first_node("background");
@@ -114,18 +115,18 @@
 	DrawCursor = HasInputFocus;
 
 	// Load the font, and possibly override the color
-    child = node->first_node("font");
-    if (child)
-    {
-        attr = child->first_attribute("resource");
-        if (attr) {
-            mFont = PageManager::FindResource(attr->value());
+	child = node->first_node("font");
+	if (child)
+	{
+		attr = child->first_attribute("resource");
+		if (attr) {
+			mFont = PageManager::FindResource(attr->value());
 			gr_getFontDetails(mFont ? mFont->GetResource() : NULL, &mFontHeight, NULL);
 		}
-    }
+	}
 
 	child = node->first_node("text");
-    if (child)  mText = child->value();
+	if (child)  mText = child->value();
 	mLastValue = gui_parse_text(mText);
 
 	child = node->first_node("data");
@@ -175,7 +176,7 @@
 		}
 	}
 
-    // Load the placement
+	// Load the placement
 	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
 	SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
 
@@ -190,17 +191,15 @@
 
 	isLocalChange = false;
 	HandleTextLocation(-3);
-
-    return;
 }
 
 GUIInput::~GUIInput()
 {
-    if (mInputText)     delete mInputText;
-	if (mBackground)    delete mBackground;
-	if (mCursor)        delete mCursor;
-	if (mFont)          delete mFont;
-	if (mAction)        delete mAction;
+	if (mInputText)	 	delete mInputText;
+	if (mBackground)	delete mBackground;
+	if (mCursor)		delete mCursor;
+	if (mFont)			delete mFont;
+	if (mAction)		delete mAction;
 }
 
 int GUIInput::HandleTextLocation(int x)
@@ -209,7 +208,8 @@
 	string displayValue, originalValue, insertChar;
 	void* fontResource = NULL;
 
-	if (mFont)  fontResource = mFont->GetResource();
+	if (mFont)
+		fontResource = mFont->GetResource();
 
 	DataManager::GetValue(mVariable, originalValue);
 	displayValue = originalValue;
@@ -229,9 +229,10 @@
 		mRendered = false;
 		return 0;
 	}
-	if (skipChars && skipChars < displayValue.size()) {
+
+	if (skipChars && skipChars < displayValue.size())
 		displayValue.erase(0, skipChars);
-	}
+
 	textWidth = gr_measureEx(displayValue.c_str(), fontResource);
 	mRendered = false;
 
@@ -239,9 +240,9 @@
 
 	if (x < -1000) {
 		// No change in scrolling
-		if (x == -1003) {
+		if (x == -1003)
 			mCursorLocation = -1;
-		}
+
 		if (mCursorLocation == -1) {
 			displayValue = originalValue;
 			skipChars = 0;
@@ -372,15 +373,15 @@
 int GUIInput::Render(void)
 {
 	if (!isConditionTrue())
-    {
-        mRendered = false;
-        return 0;
-    }
+	{
+		mRendered = false;
+		return 0;
+	}
 
 	void* fontResource = NULL;
 	if (mFont)  fontResource = mFont->GetResource();
 
-    // First step, fill background
+	// First step, fill background
 	gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
 	gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
 
@@ -394,11 +395,11 @@
 
 	int ret = 0;
 
-    // Render the text
+	// Render the text
 	mInputText->SetRenderPos(mRenderX + scrollingX, mFontY);
 	mInputText->SetMaxWidth(mRenderW - scrollingX);
-	if (mInputText)     ret = mInputText->Render();
-    if (ret < 0)        return ret;
+	if (mInputText)	 ret = mInputText->Render();
+	if (ret < 0)		return ret;
 
 	if (HasInputFocus && DrawCursor) {
 		// Render the cursor
@@ -451,21 +452,21 @@
 		gr_fill(cursorX, mFontY, CursorWidth, mFontHeight);
 	}
 
-    mRendered = true;
-    return ret;
+	mRendered = true;
+	return ret;
 }
 
 int GUIInput::Update(void)
 {
-    if (!isConditionTrue())     return (mRendered ? 2 : 0);
-    if (!mRendered)             return 2;
+	if (!isConditionTrue())	 return (mRendered ? 2 : 0);
+	if (!mRendered)			 return 2;
 
-    int ret = 0;
+	int ret = 0;
 
-    if (mInputText)         ret = mInputText->Update();
-    if (ret < 0)            return ret;
+	if (mInputText)		 ret = mInputText->Update();
+	if (ret < 0)			return ret;
 
-    return ret;
+	return ret;
 }
 
 int GUIInput::GetSelection(int x, int y)
@@ -476,14 +477,15 @@
 
 int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    static int startSelection = -1;
+	static int startSelection = -1;
 	int textWidth;
 	string displayValue, originalValue;
 	void* fontResource = NULL;
 
 	if (mFont)  fontResource = mFont->GetResource();
 
-	if (!isConditionTrue())     return -1;
+	if (!isConditionTrue())
+		return -1;
 
 	if (!HasInputFocus) {
 		if (state != TOUCH_RELEASE)
@@ -569,7 +571,7 @@
 			break;
 		}
 	}
-    return 0;
+	return 0;
 }
 
 int GUIInput::NotifyVarChange(std::string varName, std::string value)
diff --git a/gui/listbox.cpp b/gui/listbox.cpp
index 3af40ed..a4976f4 100644
--- a/gui/listbox.cpp
+++ b/gui/listbox.cpp
@@ -191,12 +191,12 @@
 
 		attr = child->first_attribute("highlightcolor");
 		memset(&mFontHighlightColor, 0, sizeof(COLOR));
-        if (attr)
-        {
-            std::string color = attr->value();
+		if (attr)
+		{
+			std::string color = attr->value();
 			ConvertStrToColor(color, &mFontHighlightColor);
 			hasFontHighlightColor = true;
-        }
+		}
 	}
 
 	// Load the separator if it exists
@@ -323,15 +323,15 @@
 
 	// Get the data for the list
 	child = node->first_node("listitem");
-    if (!child) return;
+	if (!child) return;
 	
 	while (child)
-    {
-        ListData data;
+	{
+		ListData data;
 
 		attr = child->first_attribute("name");
-        if (!attr) return;
-        data.displayName = attr->value();
+		if (!attr) return;
+		data.displayName = attr->value();
 
 		data.variableValue = child->value();
 		if (child->value() == currentValue) {
@@ -340,10 +340,10 @@
 			data.selected = 0;
 		}
 
-        mList.push_back(data);
+		mList.push_back(data);
 
-        child = child->next_sibling("listitem");
-    }
+		child = child->next_sibling("listitem");
+	}
 }
 
 GUIListBox::~GUIListBox()
@@ -430,21 +430,21 @@
 		}
 
 		if (mList.at(line + mStart).selected != 0)
-        {
-            icon = mIconSelected;
+		{
+			icon = mIconSelected;
 			currentIconHeight = mSelectedIconHeight;
 			currentIconWidth = mSelectedIconWidth;
 			currentIconOffsetY = SelectedIconOffsetY;
 			currentIconOffsetX = SelectedIconOffsetX;
-        }
-        else
-        {
-            icon = mIconUnselected;
+		}
+		else
+		{
+			icon = mIconUnselected;
 			currentIconHeight = mSelectedIconHeight;
 			currentIconWidth = mSelectedIconWidth;
 			currentIconOffsetY = SelectedIconOffsetY;
 			currentIconOffsetX = SelectedIconOffsetX;
-        }
+		}
 
 		if (icon && icon->GetResource())
 		{
@@ -758,8 +758,8 @@
 		}
 	}
 	if (varName == mVariable)
-    {
-        int i, listSize = mList.size(), selected_index = 0;
+	{
+		int i, listSize = mList.size(), selected_index = 0;
 
 		currentValue = value;
 
@@ -783,8 +783,8 @@
 		}
 
 		mUpdate = 1;
-        return 0;
-    }
+		return 0;
+	}
 	return 0;
 }
 
diff --git a/gui/objects.hpp b/gui/objects.hpp
index ff5429a..8f6f9bb 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -39,124 +39,123 @@
 class RenderObject
 {
 public:
-    enum Placement {
-        TOP_LEFT = 0,
-        TOP_RIGHT = 1,
-        BOTTOM_LEFT = 2,
-        BOTTOM_RIGHT = 3,
-        CENTER = 4,
+	enum Placement {
+		TOP_LEFT = 0,
+		TOP_RIGHT = 1,
+		BOTTOM_LEFT = 2,
+		BOTTOM_RIGHT = 3,
+		CENTER = 4,
 		CENTER_X_ONLY = 5,
-    };
+	};
 
 public:
-    RenderObject()              { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
-    virtual ~RenderObject()     {}
+	RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
+	virtual ~RenderObject() {}
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void) = 0;
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void) = 0;
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void)        { return 0; }
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void) { return 0; }
 
-    // GetRenderPos - Returns the current position of the object
-    virtual int GetRenderPos(int& x, int& y, int& w, int& h)        { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; }
+	// GetRenderPos - Returns the current position of the object
+	virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; }
 
-    // SetRenderPos - Update the position of the object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0)    { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; }
+	// SetRenderPos - Update the position of the object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; }
 
-    // GetPlacement - Returns the current placement
-    virtual int GetPlacement(Placement& placement)                  { placement = mPlacement; return 0; }
+	// GetPlacement - Returns the current placement
+	virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
 
-    // SetPlacement - Update the current placement
-    virtual int SetPlacement(Placement placement)                   { mPlacement = placement; return 0; }
+	// SetPlacement - Update the current placement
+	virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
 
-    // SetPageFocus - Notify when a page gains or loses focus
-    virtual void SetPageFocus(int inFocus)                          { return; }
+	// SetPageFocus - Notify when a page gains or loses focus
+	virtual void SetPageFocus(int inFocus) { return; }
 
 protected:
-    int mRenderX, mRenderY, mRenderW, mRenderH;
-    Placement mPlacement;
+	int mRenderX, mRenderY, mRenderW, mRenderH;
+	Placement mPlacement;
 };
 
 class ActionObject
 {
 public:
-    ActionObject()              { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
-    virtual ~ActionObject()     {}
+	ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
+	virtual ~ActionObject() {}
 
 public:
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y)        { return 0; }
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
 
-    // NotifyKey - Notify of a key press
-    //  Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
-    virtual int NotifyKey(int key)                                  { return 1; }
+	// NotifyKey - Notify of a key press
+	//  Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
+	virtual int NotifyKey(int key) { return 1; }
 
-    // GetRenderPos - Returns the current position of the object
-    virtual int GetActionPos(int& x, int& y, int& w, int& h)        { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; }
+	// GetRenderPos - Returns the current position of the object
+	virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; }
 
-    // SetRenderPos - Update the position of the object
-    //  Return 0 on success, <0 on error
-    virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
+	// SetRenderPos - Update the position of the object
+	//  Return 0 on success, <0 on error
+	virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
 
-    // IsInRegion - Checks if the request is handled by this object
-    //  Return 0 if this object handles the request, 1 if not
-    virtual int IsInRegion(int x, int y)                            { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
+	// IsInRegion - Checks if the request is handled by this object
+	//  Return 0 if this object handles the request, 1 if not
+	virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
 
-    // NotifyVarChange - Notify of a variable change
-    //  Returns 0 on success, <0 on error
-    virtual int NotifyVarChange(std::string varName, std::string value)     { return 0; }
+	// NotifyVarChange - Notify of a variable change
+	//  Returns 0 on success, <0 on error
+	virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
 
 protected:
-    int mActionX, mActionY, mActionW, mActionH;
+	int mActionX, mActionY, mActionW, mActionH;
 };
 
 class Conditional
 {
 public:
-    Conditional(xml_node<>* node);
+	Conditional(xml_node<>* node);
 
 public:
-    bool IsConditionVariable(std::string var);
-    bool isConditionTrue();
-    bool isConditionValid();
-    void NotifyPageSet();
+	bool IsConditionVariable(std::string var);
+	bool isConditionTrue();
+	bool isConditionValid();
+	void NotifyPageSet();
 
 protected:
-    class Condition
-    {
-    public:
-        std::string mVar1;
-        std::string mVar2;
-        std::string mCompareOp;
-        std::string mLastVal;
-    };
+	class Condition
+	{
+	public:
+		std::string mVar1;
+		std::string mVar2;
+		std::string mCompareOp;
+		std::string mLastVal;
+	};
 
-    std::vector<Condition> mConditions;
+	std::vector<Condition> mConditions;
 
 protected:
-    bool isMounted(std::string vol);
-    bool isConditionTrue(Condition* condition);
-
+	bool isMounted(std::string vol);
+	bool isConditionTrue(Condition* condition);
 };
 
 class InputObject
 {
 public:
-    InputObject()              { HasInputFocus = 0; }
-    virtual ~InputObject()     {}
+	InputObject() { HasInputFocus = 0; }
+	virtual ~InputObject() {}
 
 public:
-    // NotifyKeyboard - Notify of keyboard input
-    //  Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
-    virtual int NotifyKeyboard(int key)                                  { return 1; }
+	// NotifyKeyboard - Notify of keyboard input
+	//  Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
+	virtual int NotifyKeyboard(int key) { return 1; }
 
-	virtual int SetInputFocus(int focus)    { HasInputFocus = focus; return 1; }
+	virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
 
 protected:
 	int HasInputFocus;
@@ -165,26 +164,25 @@
 // Derived Objects
 // GUIText - Used for static text
 class GUIText : public RenderObject, public ActionObject, public Conditional
-
 {
 public:
-    // w and h may be ignored, in which case, no bounding box is applied
-    GUIText(xml_node<>* node);
+	// w and h may be ignored, in which case, no bounding box is applied
+	GUIText(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // Retrieve the size of the current string (dynamic strings may change per call)
-    virtual int GetCurrentBounds(int& w, int& h);
+	// Retrieve the size of the current string (dynamic strings may change per call)
+	virtual int GetCurrentBounds(int& w, int& h);
 
-    // Notify of a variable change
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// Notify of a variable change
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
 	// Set maximum width in pixels
 	virtual int SetMaxWidth(unsigned width);
@@ -196,42 +194,42 @@
 	bool isHighlighted;
 
 protected:
-    std::string mText;
-    std::string mLastValue;
-    COLOR mColor;
+	std::string mText;
+	std::string mLastValue;
+	COLOR mColor;
 	COLOR mHighlightColor;
-    Resource* mFont;
-    int mIsStatic;
-    int mVarChanged;
-    int mFontHeight;
+	Resource* mFont;
+	int mIsStatic;
+	int mVarChanged;
+	int mFontHeight;
 	unsigned maxWidth;
 	unsigned charSkip;
 	bool hasHighlightColor;
 
 protected:
-    std::string parseText(void);
+	std::string parseText(void);
 };
 
 // GUIImage - Used for static image
 class GUIImage : public RenderObject
 {
 public:
-    GUIImage(xml_node<>* node);
+	GUIImage(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // SetRenderPos - Update the position of the object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetRenderPos - Update the position of the object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
 public:
 	bool isHighlighted;
 
 protected:
-    Resource* mImage;
+	Resource* mImage;
 	Resource* mHighlightImage;
 };
 
@@ -239,46 +237,46 @@
 class GUIFill : public RenderObject
 {
 public:
-    GUIFill(xml_node<>* node);
+	GUIFill(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
 protected:
-    COLOR mColor;
+	COLOR mColor;
 };
 
 // GUIAction - Used for standard actions
 class GUIAction : public ActionObject, public Conditional
 {
 public:
-    GUIAction(xml_node<>* node);
+	GUIAction(xml_node<>* node);
 
 public:
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
-    virtual int NotifyKey(int key);
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	virtual int NotifyKey(int key);
+	virtual int NotifyVarChange(std::string varName, std::string value);
 	virtual int doActions();
 
 protected:
-    class Action
-    {
-    public:
-        std::string mFunction;
-        std::string mArg;
-    };
+	class Action
+	{
+	public:
+		std::string mFunction;
+		std::string mArg;
+	};
 
-    std::vector<Action> mActions;
-    int mKey;
+	std::vector<Action> mActions;
+	int mKey;
 
 protected:
-    int getKeyByName(std::string key);
-    virtual int doAction(Action action, int isThreaded = 0);
-    static void* thread_start(void *cookie);
+	int getKeyByName(std::string key);
+	virtual int doAction(Action action, int isThreaded = 0);
+	static void* thread_start(void *cookie);
 	void simulate_progress_bar(void);
-    int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
+	int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
 	void operation_start(const string operation_name);
 	void operation_end(const int operation_status, const int simulate);
 	static void* command_thread(void *cookie);
@@ -287,92 +285,92 @@
 class GUIConsole : public RenderObject, public ActionObject
 {
 public:
-    GUIConsole(xml_node<>* node);
+	GUIConsole(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // SetRenderPos - Update the position of the object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetRenderPos - Update the position of the object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // IsInRegion - Checks if the request is handled by this object
-    //  Return 0 if this object handles the request, 1 if not
-    virtual int IsInRegion(int x, int y);
+	// IsInRegion - Checks if the request is handled by this object
+	//  Return 0 if this object handles the request, 1 if not
+	virtual int IsInRegion(int x, int y);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
 protected:
-    enum SlideoutState
-    {
-        hidden = 0,
-        visible,
-        request_hide,
-        request_show
-    };
-    Resource* mFont;
-    Resource* mSlideoutImage;
-    COLOR mForegroundColor;
-    COLOR mBackgroundColor;
-    COLOR mScrollColor;
-    unsigned int mFontHeight;
-    int mCurrentLine;
-    unsigned int mLastCount;
-    unsigned int mMaxRows;
-    int mStartY;
-    int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
-    int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
-    int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
-    int mLastTouchX, mLastTouchY;
-    int mSlideMultiplier;
-    int mSlideout;
-    SlideoutState mSlideoutState;
+	enum SlideoutState
+	{
+		hidden = 0,
+		visible,
+		request_hide,
+		request_show
+	};
+
+	Resource* mFont;
+	Resource* mSlideoutImage;
+	COLOR mForegroundColor;
+	COLOR mBackgroundColor;
+	COLOR mScrollColor;
+	unsigned int mFontHeight;
+	int mCurrentLine;
+	unsigned int mLastCount;
+	unsigned int mMaxRows;
+	int mStartY;
+	int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
+	int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
+	int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
+	int mLastTouchX, mLastTouchY;
+	int mSlideMultiplier;
+	int mSlideout;
+	SlideoutState mSlideoutState;
 
 protected:
-    virtual int RenderSlideout(void);
-    virtual int RenderConsole(void);
-
+	virtual int RenderSlideout(void);
+	virtual int RenderConsole(void);
 };
 
 class GUIButton : public RenderObject, public ActionObject, public Conditional
 {
 public:
-    GUIButton(xml_node<>* node);
-    virtual ~GUIButton();
+	GUIButton(xml_node<>* node);
+	virtual ~GUIButton();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // SetPos - Update the position of the render object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetPos - Update the position of the render object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
 protected:
-    GUIImage* mButtonImg;
-    Resource* mButtonIcon;
-    GUIText* mButtonLabel;
-    GUIAction* mAction;
-    int mTextX, mTextY, mTextW, mTextH;
-    int mIconX, mIconY, mIconW, mIconH;
-    bool mRendered;
+	GUIImage* mButtonImg;
+	Resource* mButtonIcon;
+	GUIText* mButtonLabel;
+	GUIAction* mAction;
+	int mTextX, mTextY, mTextW, mTextH;
+	int mIconX, mIconY, mIconW, mIconH;
+	bool mRendered;
 	bool hasHighlightColor;
 	bool renderHighlight;
 	bool hasFill;
@@ -383,103 +381,103 @@
 class GUICheckbox: public RenderObject, public ActionObject, public Conditional
 {
 public:
-    GUICheckbox(xml_node<>* node);
-    virtual ~GUICheckbox();
+	GUICheckbox(xml_node<>* node);
+	virtual ~GUICheckbox();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // SetPos - Update the position of the render object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetPos - Update the position of the render object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
 protected:
-    Resource* mChecked;
-    Resource* mUnchecked;
-    GUIText* mLabel;
-    int mTextX, mTextY;
-    int mCheckX, mCheckY, mCheckW, mCheckH;
-    int mLastState;
-    bool mRendered;
-    std::string mVarName;
+	Resource* mChecked;
+	Resource* mUnchecked;
+	GUIText* mLabel;
+	int mTextX, mTextY;
+	int mCheckX, mCheckY, mCheckW, mCheckH;
+	int mLastState;
+	bool mRendered;
+	std::string mVarName;
 };
 
 class GUIFileSelector : public RenderObject, public ActionObject
 {
 public:
-    GUIFileSelector(xml_node<>* node);
-    virtual ~GUIFileSelector();
+	GUIFileSelector(xml_node<>* node);
+	virtual ~GUIFileSelector();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
-    // NotifyVarChange - Notify of a variable change
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// NotifyVarChange - Notify of a variable change
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
-    // SetPos - Update the position of the render object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetPos - Update the position of the render object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // SetPageFocus - Notify when a page gains or loses focus
-    virtual void SetPageFocus(int inFocus);
+	// SetPageFocus - Notify when a page gains or loses focus
+	virtual void SetPageFocus(int inFocus);
 
 protected:
-    struct FileData {
-        std::string fileName;
-        unsigned char fileType;     // Uses d_type format from struct dirent
-        mode_t protection;          // Uses mode_t format from stat
-        uid_t userId;
-        gid_t groupId;
-        off_t fileSize;
-        time_t lastAccess;          // Uses time_t format from stat
-        time_t lastModified;        // Uses time_t format from stat
-        time_t lastStatChange;      // Uses time_t format from stat
-    };
+	struct FileData {
+		std::string fileName;
+		unsigned char fileType;	 // Uses d_type format from struct dirent
+		mode_t protection;		  // Uses mode_t format from stat
+		uid_t userId;
+		gid_t groupId;
+		off_t fileSize;
+		time_t lastAccess;		  // Uses time_t format from stat
+		time_t lastModified;		// Uses time_t format from stat
+		time_t lastStatChange;	  // Uses time_t format from stat
+	};
 
 protected:
-    virtual int GetSelection(int x, int y);
+	virtual int GetSelection(int x, int y);
 
-    virtual int GetFileList(const std::string folder);
-    static bool fileSort(FileData d1, FileData d2);
+	virtual int GetFileList(const std::string folder);
+	static bool fileSort(FileData d1, FileData d2);
 
 protected:
-    std::vector<FileData> mFolderList;
-    std::vector<FileData> mFileList;
-    std::string mPathVar;
-    std::string mExtn;
-    std::string mVariable;
+	std::vector<FileData> mFolderList;
+	std::vector<FileData> mFileList;
+	std::string mPathVar;
+	std::string mExtn;
+	std::string mVariable;
 	std::string mSortVariable;
 	std::string mSelection;
 	std::string mHeaderText;
 	std::string mLastValue;
-    int actualLineHeight;
+	int actualLineHeight;
 	int mStart;
-    int mLineSpacing;
+	int mLineSpacing;
 	int mSeparatorH;
 	int mHeaderSeparatorH;
-    int mShowFolders, mShowFiles, mShowNavFolders;
-    int mUpdate;
-    int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
+	int mShowFolders, mShowFiles, mShowNavFolders;
+	int mUpdate;
+	int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
 	int mHeaderH;
 	int mFastScrollW;
 	int mFastScrollLineW;
@@ -493,16 +491,16 @@
 	int scrollingY;
 	int mHeaderIsStatic;
 	int touchDebounce;
-    unsigned mFontHeight;
-    unsigned mLineHeight;
-    int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
-    Resource* mHeaderIcon;
+	unsigned mFontHeight;
+	unsigned mLineHeight;
+	int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
+	Resource* mHeaderIcon;
 	Resource* mFolderIcon;
-    Resource* mFileIcon;
-    Resource* mBackground;
-    Resource* mFont;
-    COLOR mBackgroundColor;
-    COLOR mFontColor;
+	Resource* mFileIcon;
+	Resource* mBackground;
+	Resource* mFont;
+	COLOR mBackgroundColor;
+	COLOR mFontColor;
 	COLOR mHeaderBackgroundColor;
 	COLOR mHeaderFontColor;
 	COLOR mSeparatorColor;
@@ -521,56 +519,56 @@
 class GUIListBox : public RenderObject, public ActionObject
 {
 public:
-    GUIListBox(xml_node<>* node);
-    virtual ~GUIListBox();
+	GUIListBox(xml_node<>* node);
+	virtual ~GUIListBox();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
-    // NotifyVarChange - Notify of a variable change
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// NotifyVarChange - Notify of a variable change
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
-    // SetPos - Update the position of the render object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetPos - Update the position of the render object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // SetPageFocus - Notify when a page gains or loses focus
-    virtual void SetPageFocus(int inFocus);
+	// SetPageFocus - Notify when a page gains or loses focus
+	virtual void SetPageFocus(int inFocus);
 
 protected:
-    struct ListData {
-        std::string displayName;
+	struct ListData {
+		std::string displayName;
 		std::string variableValue;
 		unsigned int selected;
-    };
+	};
 
 protected:
-    virtual int GetSelection(int x, int y);
+	virtual int GetSelection(int x, int y);
 
 protected:
-    std::vector<ListData> mList;
-    std::string mVariable;
+	std::vector<ListData> mList;
+	std::string mVariable;
 	std::string mSelection;
 	std::string currentValue;
 	std::string mHeaderText;
 	std::string mLastValue;
 	int actualLineHeight;
-    int mStart;
+	int mStart;
 	int startY;
 	int mSeparatorH, mHeaderSeparatorH;
-    int mLineSpacing;
-    int mUpdate;
-    int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
+	int mLineSpacing;
+	int mUpdate;
+	int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
 	int mFastScrollW;
 	int mFastScrollLineW;
 	int mFastScrollRectW;
@@ -581,15 +579,15 @@
 	int scrollingSpeed;
 	int scrollingY;
 	static int mSortOrder;
-    unsigned mFontHeight;
-    unsigned mLineHeight;
+	unsigned mFontHeight;
+	unsigned mLineHeight;
 	Resource* mHeaderIcon;
-    Resource* mIconSelected;
-    Resource* mIconUnselected;
-    Resource* mBackground;
-    Resource* mFont;
-    COLOR mBackgroundColor;
-    COLOR mFontColor;
+	Resource* mIconSelected;
+	Resource* mIconUnselected;
+	Resource* mBackground;
+	Resource* mFont;
+	COLOR mBackgroundColor;
+	COLOR mFontColor;
 	COLOR mHeaderBackgroundColor;
 	COLOR mHeaderFontColor;
 	COLOR mSeparatorColor;
@@ -609,53 +607,51 @@
 class GUIPartitionList : public RenderObject, public ActionObject
 {
 public:
-    GUIPartitionList(xml_node<>* node);
-    virtual ~GUIPartitionList();
+	GUIPartitionList(xml_node<>* node);
+	virtual ~GUIPartitionList();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
-    // NotifyVarChange - Notify of a variable change
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// NotifyVarChange - Notify of a variable change
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
-    // SetPos - Update the position of the render object
-    //  Return 0 on success, <0 on error
-    virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+	// SetPos - Update the position of the render object
+	//  Return 0 on success, <0 on error
+	virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
 
-    // SetPageFocus - Notify when a page gains or loses focus
-    virtual void SetPageFocus(int inFocus);
+	// SetPageFocus - Notify when a page gains or loses focus
+	virtual void SetPageFocus(int inFocus);
 
 protected:
-
-protected:
-    virtual int GetSelection(int x, int y);
+	virtual int GetSelection(int x, int y);
 	virtual void MatchList(void);
 
 protected:
-    std::vector<PartitionList> mList;
+	std::vector<PartitionList> mList;
 	std::string ListType;
-    std::string mVariable;
+	std::string mVariable;
 	std::string selectedList;
 	std::string currentValue;
 	std::string mHeaderText;
 	std::string mLastValue;
 	int actualLineHeight;
-    int mStart;
+	int mStart;
 	int startY;
 	int mSeparatorH, mHeaderSeparatorH;
-    int mLineSpacing;
-    int mUpdate;
-    int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
+	int mLineSpacing;
+	int mUpdate;
+	int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
 	int mFastScrollW;
 	int mFastScrollLineW;
 	int mFastScrollRectW;
@@ -666,15 +662,15 @@
 	int scrollingSpeed;
 	int scrollingY;
 	static int mSortOrder;
-    unsigned mFontHeight;
-    unsigned mLineHeight;
+	unsigned mFontHeight;
+	unsigned mLineHeight;
 	Resource* mHeaderIcon;
-    Resource* mIconSelected;
-    Resource* mIconUnselected;
-    Resource* mBackground;
-    Resource* mFont;
-    COLOR mBackgroundColor;
-    COLOR mFontColor;
+	Resource* mIconSelected;
+	Resource* mIconUnselected;
+	Resource* mBackground;
+	Resource* mFont;
+	COLOR mBackgroundColor;
+	COLOR mFontColor;
 	COLOR mHeaderBackgroundColor;
 	COLOR mHeaderFontColor;
 	COLOR mSeparatorColor;
@@ -696,87 +692,86 @@
 class GUIAnimation : public RenderObject
 {
 public:
-    GUIAnimation(xml_node<>* node);
+	GUIAnimation(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
 protected:
-    AnimationResource* mAnimation;
-    int mFrame;
-    int mFPS;
-    int mLoop;
-    int mRender;
-    int mUpdateCount;
+	AnimationResource* mAnimation;
+	int mFrame;
+	int mFPS;
+	int mLoop;
+	int mRender;
+	int mUpdateCount;
 };
 
 class GUIProgressBar : public RenderObject, public ActionObject
 {
 public:
-    GUIProgressBar(xml_node<>* node);
+	GUIProgressBar(xml_node<>* node);
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // NotifyVarChange - Notify of a variable change
-    //  Returns 0 on success, <0 on error
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// NotifyVarChange - Notify of a variable change
+	//  Returns 0 on success, <0 on error
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
 protected:
-    Resource* mEmptyBar;
-    Resource* mFullBar;
-    std::string mMinValVar;
-    std::string mMaxValVar;
-    std::string mCurValVar;
-    float mSlide;
-    float mSlideInc;
-    int mSlideFrames;
-    int mLastPos;
+	Resource* mEmptyBar;
+	Resource* mFullBar;
+	std::string mMinValVar;
+	std::string mMaxValVar;
+	std::string mCurValVar;
+	float mSlide;
+	float mSlideInc;
+	int mSlideFrames;
+	int mLastPos;
 
 protected:
-    virtual int RenderInternal(void);       // Does the actual render
-
+	virtual int RenderInternal(void);	   // Does the actual render
 };
 
 class GUISlider : public RenderObject, public ActionObject
 {
 public:
-    GUISlider(xml_node<>* node);
-    virtual ~GUISlider();
+	GUISlider(xml_node<>* node);
+	virtual ~GUISlider();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	// NotifyTouch - Notify of a touch event
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
 protected:
-    GUIAction* sAction;
-    Resource* sSlider;
-    Resource* sSliderUsed;
-    Resource* sTouch;
-    int sTouchW, sTouchH;
-    int sCurTouchX;
-    int sUpdate;
+	GUIAction* sAction;
+	Resource* sSlider;
+	Resource* sSliderUsed;
+	Resource* sTouch;
+	int sTouchW, sTouchH;
+	int sCurTouchX;
+	int sUpdate;
 };
 
 #define MAX_KEYBOARD_LAYOUTS 5
@@ -799,7 +794,7 @@
 {
 public:
 	GUIKeyboard(xml_node<>* node);
-    virtual ~GUIKeyboard();
+	virtual ~GUIKeyboard();
 
 public:
 	virtual int Render(void);
@@ -812,12 +807,12 @@
 
 protected:
 	struct keyboard_key_class
-    {
-        unsigned char key;
+	{
+		unsigned char key;
 		unsigned char longpresskey;
-        unsigned int end_x;
+		unsigned int end_x;
 		unsigned int layout;
-    };
+	};
 
 	Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
 	struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
@@ -836,25 +831,25 @@
 class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
 {
 public:
-    // w and h may be ignored, in which case, no bounding box is applied
-    GUIInput(xml_node<>* node);
+	// w and h may be ignored, in which case, no bounding box is applied
+	GUIInput(xml_node<>* node);
 	virtual ~GUIInput();
 
 public:
-    // Render - Render the full object to the GL surface
-    //  Return 0 on success, <0 on error
-    virtual int Render(void);
+	// Render - Render the full object to the GL surface
+	//  Return 0 on success, <0 on error
+	virtual int Render(void);
 
-    // Update - Update any UI component animations (called <= 30 FPS)
-    //  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
-    virtual int Update(void);
+	// Update - Update any UI component animations (called <= 30 FPS)
+	//  Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
+	virtual int Update(void);
 
-    // Notify of a variable change
-    virtual int NotifyVarChange(std::string varName, std::string value);
+	// Notify of a variable change
+	virtual int NotifyVarChange(std::string varName, std::string value);
 
 	// NotifyTouch - Notify of a touch event
-    //  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	//  Return 0 on success, >0 to ignore remainder of touch, and <0 on error
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
 
 	virtual int NotifyKeyboard(int key);
 
@@ -865,17 +860,17 @@
 	virtual int HandleTextLocation(int x);
 
 protected:
-    GUIText* mInputText;
+	GUIText* mInputText;
 	GUIAction* mAction;
 	Resource* mBackground;
 	Resource* mCursor;
 	Resource* mFont;
 	std::string mText;
-    std::string mLastValue;
+	std::string mLastValue;
 	std::string mVariable;
 	std::string mMask;
 	std::string mMaskVariable;
-    COLOR mBackgroundColor;
+	COLOR mBackgroundColor;
 	COLOR mCursorColor;
 	int scrollingX;
 	int lastX;
diff --git a/gui/pages.cpp b/gui/pages.cpp
index 86d4dff..9aea1b8 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -50,27 +50,28 @@
 PageSet* PageManager::mCurrentSet;
 PageSet* PageManager::mBaseSet = NULL;
 
-
 // Helper routine to convert a string to a color declaration
 int ConvertStrToColor(std::string str, COLOR* color)
 {
-    // Set the default, solid black
-    memset(color, 0, sizeof(COLOR));
-    color->alpha = 255;
+	// Set the default, solid black
+	memset(color, 0, sizeof(COLOR));
+	color->alpha = 255;
 
-    // Translate variables
-    DataManager::GetValue(str, str);
-    
-    // Look for some defaults
-    if (str == "black")         return 0;
-    else if (str == "white")    { color->red = color->green = color->blue = 255; return 0; }
-    else if (str == "red")      { color->red = 255; return 0; }
-    else if (str == "green")    { color->green = 255; return 0; }
-    else if (str == "blue")     { color->blue = 255; return 0; }
+	// Translate variables
+	DataManager::GetValue(str, str);
+	
+	// Look for some defaults
+	if (str == "black")			return 0;
+	else if (str == "white")	{ color->red = color->green = color->blue = 255; return 0; }
+	else if (str == "red")		{ color->red = 255; return 0; }
+	else if (str == "green")	{ color->green = 255; return 0; }
+	else if (str == "blue")		{ color->blue = 255; return 0; }
 
-    // At this point, we require an RGB(A) color
-    if (str[0] != '#')          return -1;
-    str.erase(0, 1);
+	// At this point, we require an RGB(A) color
+	if (str[0] != '#')
+		return -1;
+
+	str.erase(0, 1);
 
 	int result;
 	if (str.size() >= 8) {
@@ -95,186 +96,188 @@
 // Helper APIs
 bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */)
 {
-    if (!node)      return false;
+	if (!node)
+		return false;
 
-    std::string value;
-    if (node->first_attribute("x"))
-    {
-        value = node->first_attribute("x")->value();
-        DataManager::GetValue(value, value);
-        *x = atol(value.c_str());
-    }
+	std::string value;
+	if (node->first_attribute("x"))
+	{
+		value = node->first_attribute("x")->value();
+		DataManager::GetValue(value, value);
+		*x = atol(value.c_str());
+	}
 
-    if (node->first_attribute("y"))
-    {
-        value = node->first_attribute("y")->value();
-        DataManager::GetValue(value, value);
-        *y = atol(value.c_str());
-    }
+	if (node->first_attribute("y"))
+	{
+		value = node->first_attribute("y")->value();
+		DataManager::GetValue(value, value);
+		*y = atol(value.c_str());
+	}
 
-    if (w && node->first_attribute("w"))
-    {
-        value = node->first_attribute("w")->value();
-        DataManager::GetValue(value, value);
-        *w = atol(value.c_str());
-    }
+	if (w && node->first_attribute("w"))
+	{
+		value = node->first_attribute("w")->value();
+		DataManager::GetValue(value, value);
+		*w = atol(value.c_str());
+	}
 
-    if (h && node->first_attribute("h"))
-    {
-        value = node->first_attribute("h")->value();
-        DataManager::GetValue(value, value);
-        *h = atol(value.c_str());
-    }
+	if (h && node->first_attribute("h"))
+	{
+		value = node->first_attribute("h")->value();
+		DataManager::GetValue(value, value);
+		*h = atol(value.c_str());
+	}
 
-    if (placement && node->first_attribute("placement"))
-    {
-        value = node->first_attribute("placement")->value();
-        DataManager::GetValue(value, value);
-        *placement = (RenderObject::Placement) atol(value.c_str());
-    }
+	if (placement && node->first_attribute("placement"))
+	{
+		value = node->first_attribute("placement")->value();
+		DataManager::GetValue(value, value);
+		*placement = (RenderObject::Placement) atol(value.c_str());
+	}
 
-    return true;
+	return true;
 }
 
 int ActionObject::SetActionPos(int x, int y, int w, int h)
 {
-    if (x < 0 || y < 0)                                     return -1;
+	if (x < 0 || y < 0)
+		return -1;
 
-    mActionX = x; 
-    mActionY = y; 
-    if (w || h)
-    {
-        mActionW = w;
-        mActionH = h;
-    }
-    return 0;
+	mActionX = x; 
+	mActionY = y; 
+	if (w || h)
+	{
+		mActionW = w;
+		mActionH = h;
+	}
+	return 0;
 }
 
 Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */)
 {
-    mTouchStart = NULL;
+	mTouchStart = NULL;
 
-    // We can memset the whole structure, because the alpha channel is ignored
-    memset(&mBackground, 0, sizeof(COLOR));
+	// We can memset the whole structure, because the alpha channel is ignored
+	memset(&mBackground, 0, sizeof(COLOR));
 
-    // With NULL, we make a console-only display
-    if (!page)
-    {
-        mName = "console";
+	// With NULL, we make a console-only display
+	if (!page)
+	{
+		mName = "console";
 
-        GUIConsole* element = new GUIConsole(NULL);
-        mRenders.push_back(element);
-        mActions.push_back(element);
-        return;
-    }
+		GUIConsole* element = new GUIConsole(NULL);
+		mRenders.push_back(element);
+		mActions.push_back(element);
+		return;
+	}
 
-    if (page->first_attribute("name"))
-        mName = page->first_attribute("name")->value();
-    else
-    {
-        LOGERR("No page name attribute found!\n");
-        return;
-    }
+	if (page->first_attribute("name"))
+		mName = page->first_attribute("name")->value();
+	else
+	{
+		LOGERR("No page name attribute found!\n");
+		return;
+	}
 
-    LOGINFO("Loading page %s\n", mName.c_str());
+	LOGINFO("Loading page %s\n", mName.c_str());
 
-    // This is a recursive routine for template handling
-    ProcessNode(page, templates);
+	// This is a recursive routine for template handling
+	ProcessNode(page, templates);
 
-    return;
+	return;
 }
 
 bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */)
 {
-    if (depth == 10)
-    {
-        LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n");
-        return false;
-    }
+	if (depth == 10)
+	{
+		LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n");
+		return false;
+	}
 
-    // Let's retrieve the background value, if any
-    xml_node<>* bg = page->first_node("background");
-    if (bg)
-    {
-        xml_attribute<>* attr = bg->first_attribute("color");
-        if (attr)
-        {
-            std::string color = attr->value();
-            ConvertStrToColor(color, &mBackground);
-        }
-    }
+	// Let's retrieve the background value, if any
+	xml_node<>* bg = page->first_node("background");
+	if (bg)
+	{
+		xml_attribute<>* attr = bg->first_attribute("color");
+		if (attr)
+		{
+			std::string color = attr->value();
+			ConvertStrToColor(color, &mBackground);
+		}
+	}
 
-    xml_node<>* child;
-    child = page->first_node("object");
-    while (child)
-    {
-        if (!child->first_attribute("type"))
-            break;
+	xml_node<>* child;
+	child = page->first_node("object");
+	while (child)
+	{
+		if (!child->first_attribute("type"))
+			break;
 
-        std::string type = child->first_attribute("type")->value();
+		std::string type = child->first_attribute("type")->value();
 
-        if (type == "text")
-        {
-            GUIText* element = new GUIText(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
-        else if (type == "image")
-        {
-            GUIImage* element = new GUIImage(child);
-            mRenders.push_back(element);
-        }
-        else if (type == "fill")
-        {
-            GUIFill* element = new GUIFill(child);
-            mRenders.push_back(element);
-        }
-        else if (type == "action")
-        {
-            GUIAction* element = new GUIAction(child);
-            mActions.push_back(element);
-        }
-        else if (type == "console")
-        {
-            GUIConsole* element = new GUIConsole(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
-        else if (type == "button")
-        {
-            GUIButton* element = new GUIButton(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
-        else if (type == "checkbox")
-        {
-            GUICheckbox* element = new GUICheckbox(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
-        else if (type == "fileselector")
-        {
-            GUIFileSelector* element = new GUIFileSelector(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
-        else if (type == "animation")
-        {
-            GUIAnimation* element = new GUIAnimation(child);
-            mRenders.push_back(element);
-        }
-        else if (type == "progressbar")
-        {
-            GUIProgressBar* element = new GUIProgressBar(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
+		if (type == "text")
+		{
+			GUIText* element = new GUIText(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
+		else if (type == "image")
+		{
+			GUIImage* element = new GUIImage(child);
+			mRenders.push_back(element);
+		}
+		else if (type == "fill")
+		{
+			GUIFill* element = new GUIFill(child);
+			mRenders.push_back(element);
+		}
+		else if (type == "action")
+		{
+			GUIAction* element = new GUIAction(child);
+			mActions.push_back(element);
+		}
+		else if (type == "console")
+		{
+			GUIConsole* element = new GUIConsole(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
+		else if (type == "button")
+		{
+			GUIButton* element = new GUIButton(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
+		else if (type == "checkbox")
+		{
+			GUICheckbox* element = new GUICheckbox(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
+		else if (type == "fileselector")
+		{
+			GUIFileSelector* element = new GUIFileSelector(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
+		else if (type == "animation")
+		{
+			GUIAnimation* element = new GUIAnimation(child);
+			mRenders.push_back(element);
+		}
+		else if (type == "progressbar")
+		{
+			GUIProgressBar* element = new GUIProgressBar(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
 		else if (type == "slider")
-        {
-            GUISlider* element = new GUISlider(child);
-            mRenders.push_back(element);
-            mActions.push_back(element);
-        }
+		{
+			GUISlider* element = new GUISlider(child);
+			mRenders.push_back(element);
+			mActions.push_back(element);
+		}
 		else if (type == "slidervalue")
 		{
 			GUISliderValue *element = new GUISliderValue(child);
@@ -306,627 +309,651 @@
 			mRenders.push_back(element);
 			mActions.push_back(element);
 		}
-        else if (type == "template")
-        {
-            if (!templates || !child->first_attribute("name"))
-            {
-                LOGERR("Invalid template request.\n");
-            }
-            else
-            {
-                std::string name = child->first_attribute("name")->value();
+		else if (type == "template")
+		{
+			if (!templates || !child->first_attribute("name"))
+			{
+				LOGERR("Invalid template request.\n");
+			}
+			else
+			{
+				std::string name = child->first_attribute("name")->value();
 
-                // We need to find the correct template
-                xml_node<>* node;
-                node = templates->first_node("template");
+				// We need to find the correct template
+				xml_node<>* node;
+				node = templates->first_node("template");
 
-                while (node)
-                {
-                    if (!node->first_attribute("name"))
-                        continue;
+				while (node)
+				{
+					if (!node->first_attribute("name"))
+						continue;
 
-                    if (name == node->first_attribute("name")->value())
-                    {
-                        if (!ProcessNode(node, templates, depth + 1))
-                            return false;
-                        else
-                            break;
-                    }
-                    node = node->next_sibling("template");
-                }
-            }
-        }
-        else
-        {
-            LOGERR("Unknown object type.\n");
-        }
-        child = child->next_sibling("object");
-    }
-    return true;
+					if (name == node->first_attribute("name")->value())
+					{
+						if (!ProcessNode(node, templates, depth + 1))
+							return false;
+						else
+							break;
+					}
+					node = node->next_sibling("template");
+				}
+			}
+		}
+		else
+		{
+			LOGERR("Unknown object type.\n");
+		}
+		child = child->next_sibling("object");
+	}
+	return true;
 }
 
 int Page::Render(void)
 {
-    // Render background
-    gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha);
-    gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+	// Render background
+	gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha);
+	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
 
-    // Render remaining objects
-    std::vector<RenderObject*>::iterator iter;
-    for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
-    {
-        if ((*iter)->Render())
-            LOGERR("A render request has failed.\n");
-    }
-    return 0;
+	// Render remaining objects
+	std::vector<RenderObject*>::iterator iter;
+	for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
+	{
+		if ((*iter)->Render())
+			LOGERR("A render request has failed.\n");
+	}
+	return 0;
 }
 
 int Page::Update(void)
 {
-    int retCode = 0;
+	int retCode = 0;
 
-    std::vector<RenderObject*>::iterator iter;
-    for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
-    {
-        int ret = (*iter)->Update();
-        if (ret < 0)
-            LOGERR("An update request has failed.\n");
-        else if (ret > retCode)
-            retCode = ret;
-    }
+	std::vector<RenderObject*>::iterator iter;
+	for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
+	{
+		int ret = (*iter)->Update();
+		if (ret < 0)
+			LOGERR("An update request has failed.\n");
+		else if (ret > retCode)
+			retCode = ret;
+	}
 
-    return retCode;
+	return retCode;
 }
 
 int Page::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    // By default, return 1 to ignore further touches if nobody is listening
-    int ret = 1;
+	// By default, return 1 to ignore further touches if nobody is listening
+	int ret = 1;
 
-    // Don't try to handle a lack of handlers
-    if (mActions.size() == 0)   return ret;
+	// Don't try to handle a lack of handlers
+	if (mActions.size() == 0)
+		return ret;
 
-    // We record mTouchStart so we can pass all the touch stream to the same handler
-    if (state == TOUCH_START)
-    {
-        std::vector<ActionObject*>::reverse_iterator iter;
-        // We work backwards, from top-most element to bottom-most element
-        for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
-        {
-            if ((*iter)->IsInRegion(x, y))
-            {
-                mTouchStart = (*iter);
-                ret = mTouchStart->NotifyTouch(state, x, y);
-                if (ret >= 0)   break;
-                mTouchStart = NULL;
-            }
-        }
-    }
-    else if (state == TOUCH_RELEASE && mTouchStart != NULL)
-    {
-        ret = mTouchStart->NotifyTouch(state, x, y);
-        mTouchStart = NULL;
-    }
-    else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL)
-    {
-        ret = mTouchStart->NotifyTouch(state, x, y);
-    }
-    return ret;
+	// We record mTouchStart so we can pass all the touch stream to the same handler
+	if (state == TOUCH_START)
+	{
+		std::vector<ActionObject*>::reverse_iterator iter;
+		// We work backwards, from top-most element to bottom-most element
+		for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
+		{
+			if ((*iter)->IsInRegion(x, y))
+			{
+				mTouchStart = (*iter);
+				ret = mTouchStart->NotifyTouch(state, x, y);
+				if (ret >= 0)
+					break;
+				mTouchStart = NULL;
+			}
+		}
+	}
+	else if (state == TOUCH_RELEASE && mTouchStart != NULL)
+	{
+		ret = mTouchStart->NotifyTouch(state, x, y);
+		mTouchStart = NULL;
+	}
+	else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL)
+	{
+		ret = mTouchStart->NotifyTouch(state, x, y);
+	}
+	return ret;
 }
 
 int Page::NotifyKey(int key)
 {
-    std::vector<ActionObject*>::reverse_iterator iter;
+	std::vector<ActionObject*>::reverse_iterator iter;
 
-    // Don't try to handle a lack of handlers
-    if (mActions.size() == 0)   return 1;
+	// Don't try to handle a lack of handlers
+	if (mActions.size() == 0)
+		return 1;
 
-    // We work backwards, from top-most element to bottom-most element
-    for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
-    {
-        int ret = (*iter)->NotifyKey(key);
-        if (ret == 0)
-            return 0;
-        else if (ret < 0)
-            LOGERR("An action handler has returned an error");
-    }
-    return 1;
+	// We work backwards, from top-most element to bottom-most element
+	for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
+	{
+		int ret = (*iter)->NotifyKey(key);
+		if (ret == 0)
+			return 0;
+		else if (ret < 0)
+			LOGERR("An action handler has returned an error");
+	}
+	return 1;
 }
 
 int Page::NotifyKeyboard(int key)
 {
-    std::vector<InputObject*>::reverse_iterator iter;
+	std::vector<InputObject*>::reverse_iterator iter;
 
-    // Don't try to handle a lack of handlers
-    if (mInputs.size() == 0)   return 1;
+	// Don't try to handle a lack of handlers
+	if (mInputs.size() == 0)
+		return 1;
 
-    // We work backwards, from top-most element to bottom-most element
-    for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
-    {
-        int ret = (*iter)->NotifyKeyboard(key);
-        if (ret == 0)
-            return 0;
-        else if (ret < 0)
-            LOGERR("A keyboard handler has returned an error");
-    }
-    return 1;
+	// We work backwards, from top-most element to bottom-most element
+	for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
+	{
+		int ret = (*iter)->NotifyKeyboard(key);
+		if (ret == 0)
+			return 0;
+		else if (ret < 0)
+			LOGERR("A keyboard handler has returned an error");
+	}
+	return 1;
 }
 
 int Page::SetKeyBoardFocus(int inFocus)
 {
-    std::vector<InputObject*>::reverse_iterator iter;
+	std::vector<InputObject*>::reverse_iterator iter;
 
-    // Don't try to handle a lack of handlers
-    if (mInputs.size() == 0)   return 1;
+	// Don't try to handle a lack of handlers
+	if (mInputs.size() == 0)
+		return 1;
 
-    // We work backwards, from top-most element to bottom-most element
-    for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
-    {
-        int ret = (*iter)->SetInputFocus(inFocus);
-        if (ret == 0)
-            return 0;
-        else if (ret < 0)
-            LOGERR("An input focus handler has returned an error");
-    }
-    return 1;
+	// We work backwards, from top-most element to bottom-most element
+	for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
+	{
+		int ret = (*iter)->SetInputFocus(inFocus);
+		if (ret == 0)
+			return 0;
+		else if (ret < 0)
+			LOGERR("An input focus handler has returned an error");
+	}
+	return 1;
 }
 
 void Page::SetPageFocus(int inFocus)
 {
-    // Render remaining objects
-    std::vector<RenderObject*>::iterator iter;
-    for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
-    {
-        (*iter)->SetPageFocus(inFocus);
-    }
-    return;
+	// Render remaining objects
+	std::vector<RenderObject*>::iterator iter;
+	for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
+		(*iter)->SetPageFocus(inFocus);
+
+	return;
 }
 
 int Page::NotifyVarChange(std::string varName, std::string value)
 {
-    std::vector<ActionObject*>::iterator iter;
+	std::vector<ActionObject*>::iterator iter;
 
-    // Don't try to handle a lack of handlers
-    if (mActions.size() == 0)   return 1;
+	// Don't try to handle a lack of handlers
+	if (mActions.size() == 0)
+		return 1;
 
-    for (iter = mActions.begin(); iter != mActions.end(); ++iter)
-    {
-        if ((*iter)->NotifyVarChange(varName, value))
-            LOGERR("An action handler errored on NotifyVarChange.\n");
-    }
-    return 0;
+	for (iter = mActions.begin(); iter != mActions.end(); ++iter)
+	{
+		if ((*iter)->NotifyVarChange(varName, value))
+			LOGERR("An action handler errored on NotifyVarChange.\n");
+	}
+	return 0;
 }
 
 PageSet::PageSet(char* xmlFile)
 {
-    mResources = NULL;
-    mCurrentPage = NULL;
-    mOverlayPage = NULL;
+	mResources = NULL;
+	mCurrentPage = NULL;
+	mOverlayPage = NULL;
 
-    mXmlFile = xmlFile;
-    if (xmlFile)
-        mDoc.parse<0>(mXmlFile);
-    else
-        mCurrentPage = new Page(NULL);
+	mXmlFile = xmlFile;
+	if (xmlFile)
+		mDoc.parse<0>(mXmlFile);
+	else
+		mCurrentPage = new Page(NULL);
 }
 
 PageSet::~PageSet()
 {
-    delete mResources;
-    free(mXmlFile);
+	delete mResources;
+	free(mXmlFile);
 }
 
 int PageSet::Load(ZipArchive* package)
 {
-    xml_node<>* parent;
-    xml_node<>* child;
-    xml_node<>* templates;
+	xml_node<>* parent;
+	xml_node<>* child;
+	xml_node<>* templates;
  
-    parent = mDoc.first_node("recovery");
-    if (!parent)
-        parent = mDoc.first_node("install");
+	parent = mDoc.first_node("recovery");
+	if (!parent)
+		parent = mDoc.first_node("install");
 
-    // Now, let's parse the XML
-    LOGINFO("Loading resources...\n");
-    child = parent->first_node("resources");
-    if (child)
-        mResources = new ResourceManager(child, package);
+	// Now, let's parse the XML
+	LOGINFO("Loading resources...\n");
+	child = parent->first_node("resources");
+	if (child)
+		mResources = new ResourceManager(child, package);
 
-    LOGINFO("Loading variables...\n");
-    child = parent->first_node("variables");
-    if (child)
-        LoadVariables(child);
+	LOGINFO("Loading variables...\n");
+	child = parent->first_node("variables");
+	if (child)
+		LoadVariables(child);
 
-    LOGINFO("Loading pages...\n");
-    // This may be NULL if no templates are present
-    templates = parent->first_node("templates");
+	LOGINFO("Loading pages...\n");
+	// This may be NULL if no templates are present
+	templates = parent->first_node("templates");
 
-    child = parent->first_node("pages");
-    if (!child)
-        return -1;
+	child = parent->first_node("pages");
+	if (!child)
+		return -1;
 
-    return LoadPages(child, templates);
+	return LoadPages(child, templates);
 }
 
 int PageSet::SetPage(std::string page)
 {
-    Page* tmp = FindPage(page);
-    if (tmp)
-    {
-        if (mCurrentPage)   mCurrentPage->SetPageFocus(0);
-        mCurrentPage = tmp;
-        mCurrentPage->SetPageFocus(1);
-        mCurrentPage->NotifyVarChange("", "");
-        return 0;
-    }
-    else
-    {
-        LOGERR("Unable to locate page (%s)\n", page.c_str());
-    }
-    return -1;
+	Page* tmp = FindPage(page);
+	if (tmp)
+	{
+		if (mCurrentPage)   mCurrentPage->SetPageFocus(0);
+		mCurrentPage = tmp;
+		mCurrentPage->SetPageFocus(1);
+		mCurrentPage->NotifyVarChange("", "");
+		return 0;
+	}
+	else
+	{
+		LOGERR("Unable to locate page (%s)\n", page.c_str());
+	}
+	return -1;
 }
 
 int PageSet::SetOverlay(Page* page)
 {
-    if (mOverlayPage)   mOverlayPage->SetPageFocus(0);
-    mOverlayPage = page;
-    if (mOverlayPage)
-    {
-        mOverlayPage->SetPageFocus(1);
-        mOverlayPage->NotifyVarChange("", "");
-    }
-    return 0;
+	if (mOverlayPage)   mOverlayPage->SetPageFocus(0);
+	mOverlayPage = page;
+	if (mOverlayPage)
+	{
+		mOverlayPage->SetPageFocus(1);
+		mOverlayPage->NotifyVarChange("", "");
+	}
+	return 0;
 }
 
 Resource* PageSet::FindResource(std::string name)
 {
-    return mResources ? mResources->FindResource(name) : NULL;
+	return mResources ? mResources->FindResource(name) : NULL;
 }
 
 Page* PageSet::FindPage(std::string name)
 {
-    std::vector<Page*>::iterator iter;
+	std::vector<Page*>::iterator iter;
 
-    for (iter = mPages.begin(); iter != mPages.end(); iter++)
-    {
-        if (name == (*iter)->GetName())
-            return (*iter);
-    }
-    return NULL;
+	for (iter = mPages.begin(); iter != mPages.end(); iter++)
+	{
+		if (name == (*iter)->GetName())
+			return (*iter);
+	}
+	return NULL;
 }
 
 int PageSet::LoadVariables(xml_node<>* vars)
 {
-    xml_node<>* child;
+	xml_node<>* child;
 
-    child = vars->first_node("variable");
-    while (child)
-    {
-        if (!child->first_attribute("name"))
-            break;
-        if (!child->first_attribute("value"))
-            break;
+	child = vars->first_node("variable");
+	while (child)
+	{
+		if (!child->first_attribute("name"))
+			break;
+		if (!child->first_attribute("value"))
+			break;
 
-        DataManager::SetValue(child->first_attribute("name")->value(), child->first_attribute("value")->value());
-        child = child->next_sibling("variable");
-    }
-    return 0;
+		DataManager::SetValue(child->first_attribute("name")->value(), child->first_attribute("value")->value());
+		child = child->next_sibling("variable");
+	}
+	return 0;
 }
 
 int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */)
 {
-    xml_node<>* child;
+	xml_node<>* child;
 
-    if (!pages)    return -1;
+	if (!pages)
+		return -1;
 
-    child = pages->first_node("page");
-    while (child != NULL)
-    {
-        Page* page = new Page(child, templates);
-        if (page->GetName().empty())
-        {
-            LOGERR("Unable to process load page\n");
-            delete page;
-        }
-        else
-        {
-            mPages.push_back(page);
-        }
-        child = child->next_sibling("page");
-    }
-    if (mPages.size() > 0)
-        return 0;
-    return -1;
+	child = pages->first_node("page");
+	while (child != NULL)
+	{
+		Page* page = new Page(child, templates);
+		if (page->GetName().empty())
+		{
+			LOGERR("Unable to process load page\n");
+			delete page;
+		}
+		else
+		{
+			mPages.push_back(page);
+		}
+		child = child->next_sibling("page");
+	}
+	if (mPages.size() > 0)
+		return 0;
+	return -1;
 }
 
 int PageSet::IsCurrentPage(Page* page)
 {
-    return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
+	return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
 }
 
 int PageSet::Render(void)
 {
-    int ret;
+	int ret;
 
-    ret = (mCurrentPage ? mCurrentPage->Render() : -1);
-    if (ret < 0)    return ret;
-    ret = (mOverlayPage ? mOverlayPage->Render() : -1);
-    return ret;
+	ret = (mCurrentPage ? mCurrentPage->Render() : -1);
+	if (ret < 0)
+		return ret;
+	ret = (mOverlayPage ? mOverlayPage->Render() : -1);
+	return ret;
 }
 
 int PageSet::Update(void)
 {
-    int ret;
+	int ret;
 
-    ret = (mCurrentPage ? mCurrentPage->Update() : -1);
-    if (ret < 0 || ret > 1)     return ret;
-    ret = (mOverlayPage ? mOverlayPage->Update() : -1);
-    return ret;
+	ret = (mCurrentPage ? mCurrentPage->Update() : -1);
+	if (ret < 0 || ret > 1)
+		return ret;
+	ret = (mOverlayPage ? mOverlayPage->Update() : -1);
+	return ret;
 }
 
 int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    if (mOverlayPage)   return (mOverlayPage->NotifyTouch(state, x, y));
-    return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
+	if (mOverlayPage)
+		return (mOverlayPage->NotifyTouch(state, x, y));
+
+	return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
 }
 
 int PageSet::NotifyKey(int key)
 {
-    if (mOverlayPage)   return (mOverlayPage->NotifyKey(key));
-    return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1);
+	if (mOverlayPage)
+		return (mOverlayPage->NotifyKey(key));
+
+	return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1);
 }
 
 int PageSet::NotifyKeyboard(int key)
 {
-    if (mOverlayPage)   return (mOverlayPage->NotifyKeyboard(key));
-    return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
+	if (mOverlayPage)
+		return (mOverlayPage->NotifyKeyboard(key));
+
+	return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
 }
 
 int PageSet::SetKeyBoardFocus(int inFocus)
 {
-    if (mOverlayPage)   return (mOverlayPage->SetKeyBoardFocus(inFocus));
-    return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
+	if (mOverlayPage)
+		return (mOverlayPage->SetKeyBoardFocus(inFocus));
+
+	return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
 }
 
 int PageSet::NotifyVarChange(std::string varName, std::string value)
 {
-    if (mOverlayPage)   mOverlayPage->NotifyVarChange(varName, value);
-    return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
+	if (mOverlayPage)
+		mOverlayPage->NotifyVarChange(varName, value);
+
+	return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
 }
 
 int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
 {
-    int fd;
-    ZipArchive zip, *pZip = NULL;
-    long len;
-    char* xmlFile = NULL;
-    PageSet* pageSet = NULL;
-    int ret;
+	int fd;
+	ZipArchive zip, *pZip = NULL;
+	long len;
+	char* xmlFile = NULL;
+	PageSet* pageSet = NULL;
+	int ret;
 
-    // Open the XML file
-    LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
-    if (mzOpenZipArchive(package.c_str(), &zip))
-    {
-        // We can try to load the XML directly...
-        struct stat st;
-        if(stat(package.c_str(),&st) != 0)
-            return -1;
+	// Open the XML file
+	LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
+	if (mzOpenZipArchive(package.c_str(), &zip))
+	{
+		// We can try to load the XML directly...
+		struct stat st;
+		if(stat(package.c_str(),&st) != 0)
+			return -1;
 
-        len = st.st_size;
-        xmlFile = (char*) malloc(len + 1);
-        if (!xmlFile)       return -1;
+		len = st.st_size;
+		xmlFile = (char*) malloc(len + 1);
+		if (!xmlFile)
+			return -1;
 
-        fd = open(package.c_str(), O_RDONLY);
-        if (fd == -1)       goto error;
+		fd = open(package.c_str(), O_RDONLY);
+		if (fd == -1)
+			goto error;
 
-        read(fd, xmlFile, len);
-        close(fd);
-    }
-    else
-    {
-        pZip = &zip;
-        const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
-        if (ui_xml == NULL)
-        {
-            LOGERR("Unable to locate ui.xml in zip file\n");
-            goto error;
-        }
-    
-        // Allocate the buffer for the file
-        len = mzGetZipEntryUncompLen(ui_xml);
-        xmlFile = (char*) malloc(len + 1);
-        if (!xmlFile)        goto error;
-    
-        if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
-        {
-            LOGERR("Unable to extract ui.xml\n");
-            goto error;
-        }
-    }
-
-    // NULL-terminate the string
-    xmlFile[len] = 0x00;
-
-    // Before loading, mCurrentSet must be the loading package so we can find resources
-    pageSet = mCurrentSet;
-    mCurrentSet = new PageSet(xmlFile);
-
-    ret = mCurrentSet->Load(pZip);
-    if (ret == 0)
-    {
-        mCurrentSet->SetPage(startpage);
-        mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
-    }
-    else
-    {
-        LOGERR("Package %s failed to load.\n", name.c_str());
-    }
+		read(fd, xmlFile, len);
+		close(fd);
+	}
+	else
+	{
+		pZip = &zip;
+		const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
+		if (ui_xml == NULL)
+		{
+			LOGERR("Unable to locate ui.xml in zip file\n");
+			goto error;
+		}
 	
-    // The first successful package we loaded is the base
-    if (mBaseSet == NULL)
-        mBaseSet = mCurrentSet;
+		// Allocate the buffer for the file
+		len = mzGetZipEntryUncompLen(ui_xml);
+		xmlFile = (char*) malloc(len + 1);
+		if (!xmlFile)
+			goto error;
+	
+		if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
+		{
+			LOGERR("Unable to extract ui.xml\n");
+			goto error;
+		}
+	}
 
-    mCurrentSet = pageSet;
+	// NULL-terminate the string
+	xmlFile[len] = 0x00;
 
-    if (pZip)   mzCloseZipArchive(pZip);
-    return ret;
+	// Before loading, mCurrentSet must be the loading package so we can find resources
+	pageSet = mCurrentSet;
+	mCurrentSet = new PageSet(xmlFile);
+
+	ret = mCurrentSet->Load(pZip);
+	if (ret == 0)
+	{
+		mCurrentSet->SetPage(startpage);
+		mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
+	}
+	else
+	{
+		LOGERR("Package %s failed to load.\n", name.c_str());
+	}
+	
+	// The first successful package we loaded is the base
+	if (mBaseSet == NULL)
+		mBaseSet = mCurrentSet;
+
+	mCurrentSet = pageSet;
+
+	if (pZip)
+		mzCloseZipArchive(pZip);
+	return ret;
 
 error:
-    LOGERR("An internal error has occurred.\n");
-    if (pZip)       mzCloseZipArchive(pZip);
-    if (xmlFile)    free(xmlFile);
-    return -1;
+	LOGERR("An internal error has occurred.\n");
+	if (pZip)
+		mzCloseZipArchive(pZip);
+	if (xmlFile)
+		free(xmlFile);
+	return -1;
 }
 
 PageSet* PageManager::FindPackage(std::string name)
 {
-    std::map<std::string, PageSet*>::iterator iter;
+	std::map<std::string, PageSet*>::iterator iter;
 
-    iter = mPageSets.find(name);
-    if (iter != mPageSets.end())
-    {
-        return (*iter).second;
-    }
-    LOGERR("Unable to locate package %s\n", name.c_str());
-    return NULL;
+	iter = mPageSets.find(name);
+	if (iter != mPageSets.end())
+		return (*iter).second;
+
+	LOGERR("Unable to locate package %s\n", name.c_str());
+	return NULL;
 }
 
 PageSet* PageManager::SelectPackage(std::string name)
 {
-    LOGINFO("Switching packages (%s)\n", name.c_str());
-    PageSet* tmp;
+	LOGINFO("Switching packages (%s)\n", name.c_str());
+	PageSet* tmp;
 
-    tmp = FindPackage(name);
-    if (tmp)
-        mCurrentSet = tmp;
-    else
-        LOGERR("Unable to find package.\n");
+	tmp = FindPackage(name);
+	if (tmp)
+		mCurrentSet = tmp;
+	else
+		LOGERR("Unable to find package.\n");
 
-    return mCurrentSet;
+	return mCurrentSet;
 }
 
 int PageManager::ReloadPackage(std::string name, std::string package)
 {
-    std::map<std::string, PageSet*>::iterator iter;
+	std::map<std::string, PageSet*>::iterator iter;
 
-    iter = mPageSets.find(name);
-    if (iter == mPageSets.end())
-        return -1;
+	iter = mPageSets.find(name);
+	if (iter == mPageSets.end())
+		return -1;
 
-    PageSet* set = (*iter).second;
-    mPageSets.erase(iter);
+	PageSet* set = (*iter).second;
+	mPageSets.erase(iter);
 
-    if (LoadPackage(name, package, "main") != 0)
-    {
-        LOGERR("Failed to load package.\n");
-        mPageSets.insert(std::pair<std::string, PageSet*>(name, set));
-        return -1;
-    }
-    if (mCurrentSet == set)     SelectPackage(name);
-    delete set;
-    return 0;
+	if (LoadPackage(name, package, "main") != 0)
+	{
+		LOGERR("Failed to load package.\n");
+		mPageSets.insert(std::pair<std::string, PageSet*>(name, set));
+		return -1;
+	}
+	if (mCurrentSet == set)
+		SelectPackage(name);
+	delete set;
+	return 0;
 }
 
 void PageManager::ReleasePackage(std::string name)
 {
-    std::map<std::string, PageSet*>::iterator iter;
+	std::map<std::string, PageSet*>::iterator iter;
 
-    iter = mPageSets.find(name);
-    if (iter == mPageSets.end())
-        return;
+	iter = mPageSets.find(name);
+	if (iter == mPageSets.end())
+		return;
 
-    PageSet* set = (*iter).second;
-    mPageSets.erase(iter);
-    delete set;
-    return;
+	PageSet* set = (*iter).second;
+	mPageSets.erase(iter);
+	delete set;
+	return;
 }
 
 int PageManager::ChangePage(std::string name)
 {
-    DataManager::SetValue("tw_operation_state", 0);
-    int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1);
-    return ret;
+	DataManager::SetValue("tw_operation_state", 0);
+	int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1);
+	return ret;
 }
 
 int PageManager::ChangeOverlay(std::string name)
 {
-    if (name.empty())
-        return mCurrentSet->SetOverlay(NULL);
-    else
-    {
-        Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL;
-        return mCurrentSet->SetOverlay(page);
-    }
+	if (name.empty())
+		return mCurrentSet->SetOverlay(NULL);
+	else
+	{
+		Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL;
+		return mCurrentSet->SetOverlay(page);
+	}
 }
 
 Resource* PageManager::FindResource(std::string name)
 {
-    return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL);
+	return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL);
 }
 
 Resource* PageManager::FindResource(std::string package, std::string name)
 {
-    PageSet* tmp;
+	PageSet* tmp;
 
-    tmp = FindPackage(name);
-    return (tmp ? tmp->FindResource(name) : NULL);
+	tmp = FindPackage(name);
+	return (tmp ? tmp->FindResource(name) : NULL);
 }
 
 int PageManager::SwitchToConsole(void)
 {
-    PageSet* console = new PageSet(NULL);
+	PageSet* console = new PageSet(NULL);
 
-    mCurrentSet = console;
-    return 0;
+	mCurrentSet = console;
+	return 0;
 }
 
 int PageManager::IsCurrentPage(Page* page)
 {
-    return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0);
+	return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0);
 }
 
 int PageManager::Render(void)
 {
-    return (mCurrentSet ? mCurrentSet->Render() : -1);
+	return (mCurrentSet ? mCurrentSet->Render() : -1);
 }
 
 int PageManager::Update(void)
 {
-    if(blankTimer.IsScreenOff())
-        return 0;
+	if(blankTimer.IsScreenOff())
+		return 0;
 
-    return (mCurrentSet ? mCurrentSet->Update() : -1);
+	return (mCurrentSet ? mCurrentSet->Update() : -1);
 }
 
 int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
+	return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
 }
 
 int PageManager::NotifyKey(int key)
 {
-    return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1);
+	return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1);
 }
 
 int PageManager::NotifyKeyboard(int key)
 {
-    return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
+	return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
 }
 
 int PageManager::SetKeyBoardFocus(int inFocus)
 {
-    return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
+	return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
 }
 
 int PageManager::NotifyVarChange(std::string varName, std::string value)
 {
-    return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
+	return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
 }
 
 extern "C" void gui_notifyVarChange(const char *name, const char* value)
 {
-    if (!gGuiRunning)   return;
+	if (!gGuiRunning)
+		return;
 
-    PageManager::NotifyVarChange(name, value);
+	PageManager::NotifyVarChange(name, value);
 }
-
diff --git a/gui/pages.hpp b/gui/pages.hpp
index 2c71735..c308c1a 100644
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -4,10 +4,10 @@
 #define _PAGES_HEADER_HPP
 
 typedef struct {
-    unsigned char red;
-    unsigned char green;
-    unsigned char blue;
-    unsigned char alpha;
+	unsigned char red;
+	unsigned char green;
+	unsigned char blue;
+	unsigned char alpha;
 } COLOR;
 
 // Utility Functions
@@ -26,110 +26,110 @@
 class Page
 {
 public:
-    virtual ~Page()             {}
+	virtual ~Page() {}
 
 public:
-    Page(xml_node<>* page, xml_node<>* templates = NULL);
-    std::string GetName(void)   { return mName; }
+	Page(xml_node<>* page, xml_node<>* templates = NULL);
+	std::string GetName(void)   { return mName; }
 
 public:
-    virtual int Render(void);
-    virtual int Update(void);
-    virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
-    virtual int NotifyKey(int key);
+	virtual int Render(void);
+	virtual int Update(void);
+	virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
+	virtual int NotifyKey(int key);
 	virtual int NotifyKeyboard(int key);
 	virtual int SetKeyBoardFocus(int inFocus);
-    virtual int NotifyVarChange(std::string varName, std::string value);
-    virtual void SetPageFocus(int inFocus);
+	virtual int NotifyVarChange(std::string varName, std::string value);
+	virtual void SetPageFocus(int inFocus);
 
 protected:
-    std::string mName;
-    std::vector<RenderObject*> mRenders;
-    std::vector<ActionObject*> mActions;
+	std::string mName;
+	std::vector<RenderObject*> mRenders;
+	std::vector<ActionObject*> mActions;
 	std::vector<InputObject*> mInputs;
 
-    ActionObject* mTouchStart;
-    COLOR mBackground;
+	ActionObject* mTouchStart;
+	COLOR mBackground;
 
 protected:
-    bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
+	bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
 };
 
 class PageSet
 {
 public:
-    PageSet(char* xmlFile);
-    virtual ~PageSet();
+	PageSet(char* xmlFile);
+	virtual ~PageSet();
 
 public:
-    int Load(ZipArchive* package);
+	int Load(ZipArchive* package);
 
-    Page* FindPage(std::string name);
-    int SetPage(std::string page);
+	Page* FindPage(std::string name);
+	int SetPage(std::string page);
 	int SetOverlay(Page* page);
-    Resource* FindResource(std::string name);
+	Resource* FindResource(std::string name);
 
-    // Helper routine for identifing if we're the current page
-    int IsCurrentPage(Page* page);
+	// Helper routine for identifing if we're the current page
+	int IsCurrentPage(Page* page);
 
-    // These are routing routines
-    int Render(void);
-    int Update(void);
-    int NotifyTouch(TOUCH_STATE state, int x, int y);
-    int NotifyKey(int key);
+	// These are routing routines
+	int Render(void);
+	int Update(void);
+	int NotifyTouch(TOUCH_STATE state, int x, int y);
+	int NotifyKey(int key);
 	int NotifyKeyboard(int key);
 	int SetKeyBoardFocus(int inFocus);
-    int NotifyVarChange(std::string varName, std::string value);
+	int NotifyVarChange(std::string varName, std::string value);
 
 protected:
-    int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
-    int LoadVariables(xml_node<>* vars);
+	int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
+	int LoadVariables(xml_node<>* vars);
 
 protected:
-    char* mXmlFile;
-    xml_document<> mDoc;
-    ResourceManager* mResources;
-    std::vector<Page*> mPages;
-    Page* mCurrentPage;
-	Page* mOverlayPage;     // This is a special case, used for "locking" the screen
+	char* mXmlFile;
+	xml_document<> mDoc;
+	ResourceManager* mResources;
+	std::vector<Page*> mPages;
+	Page* mCurrentPage;
+	Page* mOverlayPage; // This is a special case, used for "locking" the screen
 };
 
 class PageManager
 {
 public:
-    // Used by GUI
-    static int LoadPackage(std::string name, std::string package, std::string startpage);
-    static PageSet* SelectPackage(std::string name);
-    static int ReloadPackage(std::string name, std::string package);
-    static void ReleasePackage(std::string name);
+	// Used by GUI
+	static int LoadPackage(std::string name, std::string package, std::string startpage);
+	static PageSet* SelectPackage(std::string name);
+	static int ReloadPackage(std::string name, std::string package);
+	static void ReleasePackage(std::string name);
 
-    // Used for actions and pages
-    static int ChangePage(std::string name);
+	// Used for actions and pages
+	static int ChangePage(std::string name);
 	static int ChangeOverlay(std::string name);
-    static Resource* FindResource(std::string name);
-    static Resource* FindResource(std::string package, std::string name);
+	static Resource* FindResource(std::string name);
+	static Resource* FindResource(std::string package, std::string name);
 
-    // Used for console-only mode - Can be reverted via ChangePage
-    static int SwitchToConsole(void);
+	// Used for console-only mode - Can be reverted via ChangePage
+	static int SwitchToConsole(void);
 
-    // Helper to identify if a particular page is the active page
-    static int IsCurrentPage(Page* page);
+	// Helper to identify if a particular page is the active page
+	static int IsCurrentPage(Page* page);
 
-    // These are routing routines
-    static int Render(void);
-    static int Update(void);
-    static int NotifyTouch(TOUCH_STATE state, int x, int y);
-    static int NotifyKey(int key);
+	// These are routing routines
+	static int Render(void);
+	static int Update(void);
+	static int NotifyTouch(TOUCH_STATE state, int x, int y);
+	static int NotifyKey(int key);
 	static int NotifyKeyboard(int key);
 	static int SetKeyBoardFocus(int inFocus);
-    static int NotifyVarChange(std::string varName, std::string value);
+	static int NotifyVarChange(std::string varName, std::string value);
 
 protected:
-    static PageSet* FindPackage(std::string name);
+	static PageSet* FindPackage(std::string name);
 
 protected:
-    static std::map<std::string, PageSet*> mPageSets;
-    static PageSet* mCurrentSet;
+	static std::map<std::string, PageSet*> mPageSets;
+	static PageSet* mCurrentSet;
 	static PageSet* mBaseSet;
 };
 
diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp
index 36d5c16..abe0a38 100644
--- a/gui/partitionlist.cpp
+++ b/gui/partitionlist.cpp
@@ -193,12 +193,12 @@
 
 		attr = child->first_attribute("highlightcolor");
 		memset(&mFontHighlightColor, 0, sizeof(COLOR));
-        if (attr)
-        {
-            std::string color = attr->value();
+		if (attr)
+		{
+			std::string color = attr->value();
 			ConvertStrToColor(color, &mFontHighlightColor);
 			hasFontHighlightColor = true;
-        }
+		}
 	}
 
 	// Load the separator if it exists
@@ -433,21 +433,21 @@
 		}
 
 		if (mList.at(line + mStart).selected != 0)
-        {
-            icon = mIconSelected;
+		{
+			icon = mIconSelected;
 			currentIconHeight = mSelectedIconHeight;
 			currentIconWidth = mSelectedIconWidth;
 			currentIconOffsetY = SelectedIconOffsetY;
 			currentIconOffsetX = SelectedIconOffsetX;
-        }
-        else
-        {
-            icon = mIconUnselected;
+		}
+		else
+		{
+			icon = mIconUnselected;
 			currentIconHeight = mSelectedIconHeight;
 			currentIconWidth = mSelectedIconWidth;
 			currentIconOffsetY = SelectedIconOffsetY;
 			currentIconOffsetX = SelectedIconOffsetX;
-        }
+		}
 
 		if (icon && icon->GetResource())
 		{
@@ -827,8 +827,8 @@
 		}
 	}
 	if (varName == mVariable && !mUpdate)
-    {
-        if (ListType == "storage") {
+	{
+		if (ListType == "storage") {
 			int i, listSize = mList.size(), selected_index = 0;
 
 			currentValue = value;
@@ -856,8 +856,8 @@
 		}
 
 		mUpdate = 1;
-        return 0;
-    }
+		return 0;
+	}
 	return 0;
 }
 
diff --git a/gui/progressbar.cpp b/gui/progressbar.cpp
index dce4315..d53fdc1 100644
--- a/gui/progressbar.cpp
+++ b/gui/progressbar.cpp
@@ -27,188 +27,200 @@
 
 GUIProgressBar::GUIProgressBar(xml_node<>* node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mEmptyBar = NULL;
-    mFullBar = NULL;
-    mLastPos = 0;
-    mSlide = 0.0;
-    mSlideInc = 0.0;
+	mEmptyBar = NULL;
+	mFullBar = NULL;
+	mLastPos = 0;
+	mSlide = 0.0;
+	mSlideInc = 0.0;
 
-    if (!node)
-    {
-        LOGERR("GUIProgressBar created without XML node\n");
-        return;
-    }
+	if (!node)
+	{
+		LOGERR("GUIProgressBar created without XML node\n");
+		return;
+	}
 
-    child = node->first_node("resource");
-    if (child)
-    {
-        attr = child->first_attribute("empty");
-        if (attr)
-            mEmptyBar = PageManager::FindResource(attr->value());
+	child = node->first_node("resource");
+	if (child)
+	{
+		attr = child->first_attribute("empty");
+		if (attr)
+			mEmptyBar = PageManager::FindResource(attr->value());
 
-        attr = child->first_attribute("full");
-        if (attr)
-            mFullBar = PageManager::FindResource(attr->value());
-    }
+		attr = child->first_attribute("full");
+		if (attr)
+			mFullBar = PageManager::FindResource(attr->value());
+	}
 
-    // Load the placement
-    LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
+	// Load the placement
+	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
 
-    // Load the data
-    child = node->first_node("data");
-    if (child)
-    {
-        attr = child->first_attribute("min");
-        if (attr)   mMinValVar = attr->value();
+	// Load the data
+	child = node->first_node("data");
+	if (child)
+	{
+		attr = child->first_attribute("min");
+		if (attr)   mMinValVar = attr->value();
 
-        attr = child->first_attribute("max");
-        if (attr)   mMaxValVar = attr->value();
+		attr = child->first_attribute("max");
+		if (attr)   mMaxValVar = attr->value();
 
-        attr = child->first_attribute("name");
-        if (attr)   mCurValVar = attr->value();
-    }
+		attr = child->first_attribute("name");
+		if (attr)   mCurValVar = attr->value();
+	}
 
-    if (mEmptyBar && mEmptyBar->GetResource())
-    {
-        mRenderW = gr_get_width(mEmptyBar->GetResource());
-        mRenderH = gr_get_height(mEmptyBar->GetResource());
-    }
+	if (mEmptyBar && mEmptyBar->GetResource())
+	{
+		mRenderW = gr_get_width(mEmptyBar->GetResource());
+		mRenderH = gr_get_height(mEmptyBar->GetResource());
+	}
 
-    return;
+	return;
 }
 
 int GUIProgressBar::Render(void)
 {
-    // This handles making sure timing updates occur
-    Update();
-    return RenderInternal();
+	// This handles making sure timing updates occur
+	Update();
+	return RenderInternal();
 }
 
 int GUIProgressBar::RenderInternal(void)
 {
-    if (!mEmptyBar || !mEmptyBar->GetResource())    return -1;
-    if (!mFullBar || !mFullBar->GetResource())      return -1;
+	if (!mEmptyBar || !mEmptyBar->GetResource())
+		return -1;
 
-    gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
-    gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY);
-    return 0;
+	if (!mFullBar || !mFullBar->GetResource())
+		return -1;
+
+	gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+	gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY);
+	return 0;
 }
 
 int GUIProgressBar::Update(void)
 {
-    std::string str;
-    int min, max, cur, pos;
+	std::string str;
+	int min, max, cur, pos;
 
-    if (mMinValVar.empty())     min = 0;
-    else
-    {
-        str.clear();
-        if (atoi(mMinValVar.c_str()) != 0)      str = mMinValVar;
-        else                                    DataManager::GetValue(mMinValVar, str);
-        min = atoi(str.c_str());
-    }
+	if (mMinValVar.empty())
+		min = 0;
+	else
+	{
+		str.clear();
+		if (atoi(mMinValVar.c_str()) != 0)
+			str = mMinValVar;
+		else
+			DataManager::GetValue(mMinValVar, str);
+		min = atoi(str.c_str());
+	}
 
-    if (mMaxValVar.empty())     max = 100;
-    else
-    {
-        str.clear();
-        if (atoi(mMaxValVar.c_str()) != 0)      str = mMaxValVar;
-        else                                    DataManager::GetValue(mMaxValVar, str);
-        max = atoi(str.c_str());
-    }
+	if (mMaxValVar.empty())
+		max = 100;
+	else
+	{
+		str.clear();
+		if (atoi(mMaxValVar.c_str()) != 0)
+			str = mMaxValVar;
+		else
+			DataManager::GetValue(mMaxValVar, str);
+		max = atoi(str.c_str());
+	}
 
-    str.clear();
-    DataManager::GetValue(mCurValVar, str);
-    cur = atoi(str.c_str());
+	str.clear();
+	DataManager::GetValue(mCurValVar, str);
+	cur = atoi(str.c_str());
 
-    // Do slide, if needed
-    if (mSlideFrames)
-    {
-        mSlide += mSlideInc;
-        mSlideFrames--;
-        if (cur != (int) mSlide)
-        {
-            cur = (int) mSlide;
-            DataManager::SetValue(mCurValVar, cur);
-        }
-    }
+	// Do slide, if needed
+	if (mSlideFrames)
+	{
+		mSlide += mSlideInc;
+		mSlideFrames--;
+		if (cur != (int) mSlide)
+		{
+			cur = (int) mSlide;
+			DataManager::SetValue(mCurValVar, cur);
+		}
+	}
 
-    // Normalize to 0
-    max -= min;
-    cur -= min;
-    min = 0;
+	// Normalize to 0
+	max -= min;
+	cur -= min;
+	min = 0;
 
-    if (cur < min)  cur = min;
-    if (cur > max)  cur = max;
+	if (cur < min)  cur = min;
+	if (cur > max)  cur = max;
 
-    if (max == 0)   pos = 0;
-    else            pos = (cur * mRenderW) / max;
+	if (max == 0)   pos = 0;
+	else            pos = (cur * mRenderW) / max;
 
-    if (pos == mLastPos)            return 0;
-    mLastPos = pos;
-    if (RenderInternal() != 0)      return -1;
-    return 2;
+	if (pos == mLastPos)
+		return 0;
+
+	mLastPos = pos;
+
+	if (RenderInternal() != 0)
+		return -1;
+	return 2;
 }
 
 int GUIProgressBar::NotifyVarChange(std::string varName, std::string value)
 {
-    static int nextPush = 0;
+	static int nextPush = 0;
 
-    if (varName.empty())
-    {
-        nextPush = 0;
-        mLastPos = 0;
-        mSlide = 0.0;
-        mSlideInc = 0.0;
-        return 0;
-    }
+	if (varName.empty())
+	{
+		nextPush = 0;
+		mLastPos = 0;
+		mSlide = 0.0;
+		mSlideInc = 0.0;
+		return 0;
+	}
 
-    if (varName == "ui_progress_portion" || varName == "ui_progress_frames")
-    {
-        std::string str;
-        int cur;
+	if (varName == "ui_progress_portion" || varName == "ui_progress_frames")
+	{
+		std::string str;
+		int cur;
 
-        if (mSlideFrames)
-        {
-            mSlide += (mSlideInc * mSlideFrames);
-            cur = (int) mSlide;
-            DataManager::SetValue(mCurValVar, cur);
-            mSlideFrames = 0;
-        }
+		if (mSlideFrames)
+		{
+			mSlide += (mSlideInc * mSlideFrames);
+			cur = (int) mSlide;
+			DataManager::SetValue(mCurValVar, cur);
+			mSlideFrames = 0;
+		}
 
-        if (nextPush)
-        {
-            mSlide += nextPush;
-            cur = (int) mSlide;
-            DataManager::SetValue(mCurValVar, cur);
-            nextPush = 0;
-        }
+		if (nextPush)
+		{
+			mSlide += nextPush;
+			cur = (int) mSlide;
+			DataManager::SetValue(mCurValVar, cur);
+			nextPush = 0;
+		}
 
-        if (varName == "ui_progress_portion")   mSlide = atof(value.c_str());
-        else
-        {
-            mSlideFrames = atol(value.c_str());
-            if (mSlideFrames == 0)
-            {
-                // We're just holding this progress until the next push
-                nextPush = mSlide;
-            }
-        }
+		if (varName == "ui_progress_portion")   mSlide = atof(value.c_str());
+		else
+		{
+			mSlideFrames = atol(value.c_str());
+			if (mSlideFrames == 0)
+			{
+				// We're just holding this progress until the next push
+				nextPush = mSlide;
+			}
+		}
 
-        if (mSlide > 0 && mSlideFrames > 0)
-        {
-            // Get the current position
-            str.clear();
-            DataManager::GetValue(mCurValVar, str);
-            cur = atoi(str.c_str());
+		if (mSlide > 0 && mSlideFrames > 0)
+		{
+			// Get the current position
+			str.clear();
+			DataManager::GetValue(mCurValVar, str);
+			cur = atoi(str.c_str());
 
-            mSlideInc = (float) mSlide / (float) mSlideFrames;
-            mSlide = cur;
-        }
-    }
-    return 0;
+			mSlideInc = (float) mSlide / (float) mSlideFrames;
+			mSlide = cur;
+		}
+	}
+	return 0;
 }
-
diff --git a/gui/resources.cpp b/gui/resources.cpp
index aaa1533..6babc57 100644
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -32,59 +32,56 @@
 
 Resource::Resource(xml_node<>* node, ZipArchive* pZip)
 {
-    if (node && node->first_attribute("name"))
-        mName = node->first_attribute("name")->value();
+	if (node && node->first_attribute("name"))
+		mName = node->first_attribute("name")->value();
 }
 
-
-int Resource::ExtractResource(ZipArchive* pZip, 
-                              std::string folderName, 
-                              std::string fileName, 
-                              std::string fileExtn, 
-                              std::string destFile)
+int Resource::ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile)
 {
-    if (!pZip)  return -1;
+	if (!pZip)
+		return -1;
 
-    std::string src = folderName + "/" + fileName + fileExtn;
+	std::string src = folderName + "/" + fileName + fileExtn;
 
 	const ZipEntry* binary = mzFindZipEntry(pZip, src.c_str());
-    if (binary == NULL) {
-        return -1;
+	if (binary == NULL) {
+		return -1;
 	}
 
-    unlink(destFile.c_str());
-    int fd = creat(destFile.c_str(), 0666);
-    if (fd < 0)
-        return -1;
+	unlink(destFile.c_str());
+	int fd = creat(destFile.c_str(), 0666);
+	if (fd < 0)
+		return -1;
 
-    int ret = 0;
-    if (!mzExtractZipEntryToFile(pZip, binary, fd))
-        ret = -1;
+	int ret = 0;
+	if (!mzExtractZipEntryToFile(pZip, binary, fd))
+		ret = -1;
 
-    close(fd);
-    return ret;
+	close(fd);
+	return ret;
 }
 
 FontResource::FontResource(xml_node<>* node, ZipArchive* pZip)
  : Resource(node, pZip)
 {
-    std::string file;
+	std::string file;
 
-    mFont = NULL;
-    if (!node)  return;
+	mFont = NULL;
+	if (!node)
+		return;
 
-    if (node->first_attribute("filename"))
-        file = node->first_attribute("filename")->value();
+	if (node->first_attribute("filename"))
+		file = node->first_attribute("filename")->value();
 
-    if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
-    {
-        mFont = gr_loadFont(TMP_RESOURCE_NAME);
-        unlink(TMP_RESOURCE_NAME);
-    }
-    else
-    {
-        mFont = gr_loadFont(file.c_str());
-    }
+	if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
+	{
+		mFont = gr_loadFont(TMP_RESOURCE_NAME);
+		unlink(TMP_RESOURCE_NAME);
+	}
+	else
+	{
+		mFont = gr_loadFont(file.c_str());
+	}
 }
 
 FontResource::~FontResource()
@@ -94,115 +91,118 @@
 ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip)
  : Resource(node, pZip)
 {
-    std::string file;
+	std::string file;
 
-    mSurface = NULL;
-    if (!node)  return;
+	mSurface = NULL;
+	if (!node)
+		return;
 
-    if (node->first_attribute("filename"))
-        file = node->first_attribute("filename")->value();
+	if (node->first_attribute("filename"))
+		file = node->first_attribute("filename")->value();
 
-    if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
-    {
-        res_create_surface(TMP_RESOURCE_NAME, &mSurface);
-        unlink(TMP_RESOURCE_NAME);
-    } else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
-    {
-        // JPG includes the .jpg extension in the filename so extension should be blank
+	if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
+	{
 		res_create_surface(TMP_RESOURCE_NAME, &mSurface);
-        unlink(TMP_RESOURCE_NAME);
-    }
-    else
+		unlink(TMP_RESOURCE_NAME);
+	}
+	else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
+	{
+		// JPG includes the .jpg extension in the filename so extension should be blank
+		res_create_surface(TMP_RESOURCE_NAME, &mSurface);
+		unlink(TMP_RESOURCE_NAME);
+	}
+	else
 		res_create_surface(file.c_str(), &mSurface);
 }
 
 ImageResource::~ImageResource()
 {
-    if (mSurface)
-        res_free_surface(mSurface);
+	if (mSurface)
+		res_free_surface(mSurface);
 }
 
 AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip)
  : Resource(node, pZip)
 {
-    std::string file;
-    int fileNum = 1;
+	std::string file;
+	int fileNum = 1;
 
-    if (!node)  return;
+	if (!node)
+		return;
 
-    if (node->first_attribute("filename"))
-        file = node->first_attribute("filename")->value();
+	if (node->first_attribute("filename"))
+		file = node->first_attribute("filename")->value();
 
-    for ( ; ; )
-    {
-        std::ostringstream fileName;
-        fileName << file << std::setfill ('0') << std::setw (3) << fileNum;
+	for (;;)
+	{
+		std::ostringstream fileName;
+		fileName << file << std::setfill ('0') << std::setw (3) << fileNum;
 
-        gr_surface surface;
-        if (pZip)
-        {
-            if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0)
-                break;
-    
-            if (res_create_surface(TMP_RESOURCE_NAME, &surface))
-                break;
+		gr_surface surface;
+		if (pZip)
+		{
+			if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0)
+				break;
+	
+			if (res_create_surface(TMP_RESOURCE_NAME, &surface))
+				break;
 
-            unlink(TMP_RESOURCE_NAME);
-        }
-        else
-        {
-            if (res_create_surface(fileName.str().c_str(), &surface))
-                break;
-        }
-        mSurfaces.push_back(surface);
-        fileNum++;
-    }
+			unlink(TMP_RESOURCE_NAME);
+		}
+		else
+		{
+			if (res_create_surface(fileName.str().c_str(), &surface))
+				break;
+		}
+		mSurfaces.push_back(surface);
+		fileNum++;
+	}
 }
 
 AnimationResource::~AnimationResource()
 {
-    std::vector<gr_surface>::iterator it;
+	std::vector<gr_surface>::iterator it;
 
-    for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it)
-    {
-        res_free_surface(*it);
-    }
-    mSurfaces.clear();
+	for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it)
+		res_free_surface(*it);
+
+	mSurfaces.clear();
 }
 
 Resource* ResourceManager::FindResource(std::string name)
 {
-    std::vector<Resource*>::iterator iter;
+	std::vector<Resource*>::iterator iter;
 
-    for (iter = mResources.begin(); iter != mResources.end(); iter++)
-    {
-        if (name == (*iter)->GetName())
-            return (*iter);
-    }
-    return NULL;
+	for (iter = mResources.begin(); iter != mResources.end(); iter++)
+	{
+		if (name == (*iter)->GetName())
+			return (*iter);
+	}
+	return NULL;
 }
 
 ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip)
 {
-    xml_node<>* child;
+	xml_node<>* child;
 
-    if (!resList)       return;
+	if (!resList)
+		return;
 
-    child = resList->first_node("resource");
-    while (child != NULL)
-    {
-        xml_attribute<>* attr = child->first_attribute("type");
-        if (!attr)
-            break;
+	child = resList->first_node("resource");
+	while (child != NULL)
+	{
+		xml_attribute<>* attr = child->first_attribute("type");
+		if (!attr)
+			break;
 
 		std::string type = attr->value();
 
-        if (type == "font")
-        {
-            FontResource* res = new FontResource(child, pZip);
-            if (res == NULL || res->GetResource() == NULL)
-            {
-                xml_attribute<>* attr_name = child->first_attribute("name");
+		if (type == "font")
+		{
+			FontResource* res = new FontResource(child, pZip);
+			if (res == NULL || res->GetResource() == NULL)
+			{
+				xml_attribute<>* attr_name = child->first_attribute("name");
 
 				if (!attr_name) {
 					std::string res_name = attr_name->value();
@@ -210,39 +210,19 @@
 				} else
 					LOGERR("Resource type (%s) failed to load\n", type.c_str());
 
-                delete res;
-            }
-            else
-            {
-                mResources.push_back((Resource*) res);
-            }
-        }
-        else if (type == "image")
-        {
-			ImageResource* res = new ImageResource(child, pZip);
-            if (res == NULL || res->GetResource() == NULL)
-            {
-                xml_attribute<>* attr_name = child->first_attribute("name");
-
-				if (!attr_name) {
-					std::string res_name = attr_name->value();
-					LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
-				} else
-					LOGERR("Resource type (%s) failed to load\n", type.c_str());
-
-                delete res;
-            }
-            else
-            {
+				delete res;
+			}
+			else
+			{
 				mResources.push_back((Resource*) res);
-            }
-        }
-        else if (type == "animation")
-        {
-            AnimationResource* res = new AnimationResource(child, pZip);
-            if (res == NULL || res->GetResource() == NULL)
-            {
-                xml_attribute<>* attr_name = child->first_attribute("name");
+			}
+		}
+		else if (type == "image")
+		{
+			ImageResource* res = new ImageResource(child, pZip);
+			if (res == NULL || res->GetResource() == NULL)
+			{
+				xml_attribute<>* attr_name = child->first_attribute("name");
 
 				if (!attr_name) {
 					std::string res_name = attr_name->value();
@@ -250,30 +230,48 @@
 				} else
 					LOGERR("Resource type (%s) failed to load\n", type.c_str());
 
-                delete res;
-            }
-            else
-            {
-                mResources.push_back((Resource*) res);
-            }
-        }
-        else
-        {
-            LOGERR("Resource type (%s) not supported.\n", type.c_str());
-        }
+				delete res;
+			}
+			else
+			{
+				mResources.push_back((Resource*) res);
+			}
+		}
+		else if (type == "animation")
+		{
+			AnimationResource* res = new AnimationResource(child, pZip);
+			if (res == NULL || res->GetResource() == NULL)
+			{
+				xml_attribute<>* attr_name = child->first_attribute("name");
 
-        child = child->next_sibling("resource");
-    }
+				if (!attr_name) {
+					std::string res_name = attr_name->value();
+					LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
+				} else
+					LOGERR("Resource type (%s) failed to load\n", type.c_str());
+
+				delete res;
+			}
+			else
+			{
+				mResources.push_back((Resource*) res);
+			}
+		}
+		else
+		{
+			LOGERR("Resource type (%s) not supported.\n", type.c_str());
+		}
+
+		child = child->next_sibling("resource");
+	}
 }
 
 ResourceManager::~ResourceManager()
 {
-    std::vector<Resource*>::iterator iter;
+	std::vector<Resource*>::iterator iter;
 
-    for (iter = mResources.begin(); iter != mResources.end(); iter++)
-    {
-        delete *iter;
-    }
-    mResources.clear();
+	for (iter = mResources.begin(); iter != mResources.end(); iter++)
+		delete *iter;
+
+	mResources.clear();
 }
-
diff --git a/gui/resources.hpp b/gui/resources.hpp
index 6cb5da2..4e05e41 100644
--- a/gui/resources.hpp
+++ b/gui/resources.hpp
@@ -7,24 +7,24 @@
 class Resource
 {
 public:
-    Resource(xml_node<>* node, ZipArchive* pZip);
-    virtual ~Resource()         {}
+	Resource(xml_node<>* node, ZipArchive* pZip);
+	virtual ~Resource() {}
 
 public:
-    virtual void* GetResource(void) = 0;
-    std::string GetName(void) { return mName; }
+	virtual void* GetResource(void) = 0;
+	std::string GetName(void) { return mName; }
 
 private:
-    std::string mName;
+	std::string mName;
 
 protected:
-    static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
+	static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
 };
 
 typedef enum {
-    TOUCH_START = 0, 
-    TOUCH_DRAG = 1,
-    TOUCH_RELEASE = 2,
+	TOUCH_START = 0, 
+	TOUCH_DRAG = 1,
+	TOUCH_RELEASE = 2,
 	TOUCH_HOLD = 3,
 	TOUCH_REPEAT = 4
 } TOUCH_STATE;
@@ -32,56 +32,55 @@
 class FontResource : public Resource
 {
 public:
-    FontResource(xml_node<>* node, ZipArchive* pZip);
-    virtual ~FontResource();
+	FontResource(xml_node<>* node, ZipArchive* pZip);
+	virtual ~FontResource();
 
 public:
-    virtual void* GetResource(void) { return mFont; }
+	virtual void* GetResource(void) { return mFont; }
 
 protected:
-    void* mFont;
+	void* mFont;
 };
 
 class ImageResource : public Resource
 {
 public:
-    ImageResource(xml_node<>* node, ZipArchive* pZip);
-    virtual ~ImageResource();
+	ImageResource(xml_node<>* node, ZipArchive* pZip);
+	virtual ~ImageResource();
 
 public:
-    virtual void* GetResource(void) { return mSurface; }
+	virtual void* GetResource(void) { return mSurface; }
 
 protected:
-    gr_surface mSurface;
+	gr_surface mSurface;
 };
 
 class AnimationResource : public Resource
 {
 public:
-    AnimationResource(xml_node<>* node, ZipArchive* pZip);
-    virtual ~AnimationResource();
+	AnimationResource(xml_node<>* node, ZipArchive* pZip);
+	virtual ~AnimationResource();
 
 public:
-    virtual void* GetResource(void)         { return mSurfaces.at(0); }
-    virtual void* GetResource(int entry)    { return mSurfaces.at(entry); }
-    virtual int GetResourceCount(void)      { return mSurfaces.size(); }
+	virtual void* GetResource(void) { return mSurfaces.at(0); }
+	virtual void* GetResource(int entry) { return mSurfaces.at(entry); }
+	virtual int GetResourceCount(void) { return mSurfaces.size(); }
 
 protected:
-    std::vector<gr_surface> mSurfaces;
+	std::vector<gr_surface> mSurfaces;
 };
 
 class ResourceManager
 {
 public:
-    ResourceManager(xml_node<>* resList, ZipArchive* pZip);
-    virtual ~ResourceManager();
+	ResourceManager(xml_node<>* resList, ZipArchive* pZip);
+	virtual ~ResourceManager();
 
 public:
-    Resource* FindResource(std::string name);
+	Resource* FindResource(std::string name);
 
 private:
-    std::vector<Resource*> mResources;
+	std::vector<Resource*> mResources;
 };
 
 #endif  // _RESOURCE_HEADER
-
diff --git a/gui/slider.cpp b/gui/slider.cpp
index 4542d60..b46d156 100644
--- a/gui/slider.cpp
+++ b/gui/slider.cpp
@@ -28,143 +28,143 @@
 
 GUISlider::GUISlider(xml_node<>* node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    sAction = NULL;
-    sSlider = NULL;
-    sSliderUsed = NULL;
-    sTouch = NULL;
-    sTouchW = 20;
+	sAction = NULL;
+	sSlider = NULL;
+	sSliderUsed = NULL;
+	sTouch = NULL;
+	sTouchW = 20;
 
-    if (!node)
-    {
-        LOGERR("GUISlider created without XML node\n");
-        return;
-    }
+	if (!node)
+	{
+		LOGERR("GUISlider created without XML node\n");
+		return;
+	}
 
-    child = node->first_node("resource");
-    if (child)
-    {
-        attr = child->first_attribute("base");
-        if (attr)
-            sSlider = PageManager::FindResource(attr->value());
+	child = node->first_node("resource");
+	if (child)
+	{
+		attr = child->first_attribute("base");
+		if (attr)
+			sSlider = PageManager::FindResource(attr->value());
 
-        attr = child->first_attribute("used");
-        if (attr)
-            sSliderUsed = PageManager::FindResource(attr->value());
+		attr = child->first_attribute("used");
+		if (attr)
+			sSliderUsed = PageManager::FindResource(attr->value());
 
-        attr = child->first_attribute("touch");
-        if (attr)
-            sTouch = PageManager::FindResource(attr->value());
-    }
+		attr = child->first_attribute("touch");
+		if (attr)
+			sTouch = PageManager::FindResource(attr->value());
+	}
 
-    // Load the placement
+	// Load the placement
 	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
 
-    if (sSlider && sSlider->GetResource())
-    {
+	if (sSlider && sSlider->GetResource())
+	{
 		mRenderW = gr_get_width(sSlider->GetResource());
-        mRenderH = gr_get_height(sSlider->GetResource());
-    }
-    if (sTouch && sTouch->GetResource())
-    {
-        sTouchW = gr_get_width(sTouch->GetResource());  // Width of the "touch image" that follows the touch (arrow)
-        sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow)
-    }
+		mRenderH = gr_get_height(sSlider->GetResource());
+	}
+	if (sTouch && sTouch->GetResource())
+	{
+		sTouchW = gr_get_width(sTouch->GetResource());  // Width of the "touch image" that follows the touch (arrow)
+		sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow)
+	}
 
-    //LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW);
+	//LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW);
 	mActionX = mRenderX;
-    mActionY = mRenderY;
-    mActionW = mRenderW;
-    mActionH = mRenderH;
+	mActionY = mRenderY;
+	mActionW = mRenderW;
+	mActionH = mRenderH;
 
-    sAction = new GUIAction(node);
+	sAction = new GUIAction(node);
 
-    sCurTouchX = mRenderX;
-    sUpdate = 1;
-
-    return;
+	sCurTouchX = mRenderX;
+	sUpdate = 1;
 }
 
 GUISlider::~GUISlider()
 {
-    delete sAction;
+	delete sAction;
 }
 
 int GUISlider::Render(void)
 {
-    if (!sSlider || !sSlider->GetResource())       return -1;
+	if (!sSlider || !sSlider->GetResource())
+		return -1;
 
-    // Draw the slider
-    gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+	// Draw the slider
+	gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
 
-    // Draw the used
-    if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX)
-    {
-        gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY);
-    }
+	// Draw the used
+	if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX)
+		gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY);
 
-    // Draw the touch icon
-    if (sTouch && sTouch->GetResource())
-    {
-        gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2)));
-    }
+	// Draw the touch icon
+	if (sTouch && sTouch->GetResource())
+		gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2)));
 
-    sUpdate = 0;
-    return 0;
+	sUpdate = 0;
+	return 0;
 }
 
 int GUISlider::Update(void)
 {
-    if (sUpdate)    return 2;
-    return 0;
+	if (sUpdate)
+		return 2;
+	return 0;
 }
 
 int GUISlider::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-    static bool dragging = false;
+	static bool dragging = false;
 
 	switch (state)
-    {
-    case TOUCH_START:
-        if (x >= mRenderX && x <= mRenderX + sTouchW && 
-            y >= mRenderY && y <= mRenderY + mRenderH)
-        {
-            sCurTouchX = x - (sTouchW / 2);
-            if (sCurTouchX < mRenderX)  sCurTouchX = mRenderX;
-            dragging = true;
-        }
-        break;
+	{
+	case TOUCH_START:
+		if (x >= mRenderX && x <= mRenderX + sTouchW && 
+			y >= mRenderY && y <= mRenderY + mRenderH)
+		{
+			sCurTouchX = x - (sTouchW / 2);
+			if (sCurTouchX < mRenderX)
+				sCurTouchX = mRenderX;
+			dragging = true;
+		}
+		break;
 
-    case TOUCH_DRAG:
-        if (!dragging)  return 0;
-        if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2))
-        {
-            sCurTouchX = mRenderX;
-            dragging = false;
-            sUpdate = 1;
-            break;
-        }
-        sCurTouchX = x - (sTouchW / 2);
-        if (sCurTouchX < mRenderX)                          sCurTouchX = mRenderX;
-        if (sCurTouchX > mRenderX + mRenderW - sTouchW)     sCurTouchX = mRenderX + mRenderW - sTouchW;
-        sUpdate = 1;
-        break;
+	case TOUCH_DRAG:
+		if (!dragging)
+			return 0;
+		if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2))
+		{
+			sCurTouchX = mRenderX;
+			dragging = false;
+			sUpdate = 1;
+			break;
+		}
+		sCurTouchX = x - (sTouchW / 2);
+		if (sCurTouchX < mRenderX)
+			sCurTouchX = mRenderX;
+		if (sCurTouchX > mRenderX + mRenderW - sTouchW)
+			sCurTouchX = mRenderX + mRenderW - sTouchW;
+		sUpdate = 1;
+		break;
 
-    case TOUCH_RELEASE:
-        if (!dragging)  return 0;
-        if (sCurTouchX >= mRenderX + mRenderW - sTouchW)
-        {
-            sAction->doActions();
-        }
-        sCurTouchX = mRenderX;
-        dragging = false;
-        sUpdate = 1;
+	case TOUCH_RELEASE:
+		if (!dragging)
+			return 0;
+
+		if (sCurTouchX >= mRenderX + mRenderW - sTouchW)
+			sAction->doActions();
+
+		sCurTouchX = mRenderX;
+		dragging = false;
+		sUpdate = 1;
 	case TOUCH_REPEAT:
 	case TOUCH_HOLD:
-        break;
-    }
-    return 0;
+		break;
+	}
+	return 0;
 }
-
diff --git a/gui/text.cpp b/gui/text.cpp
index 46a6622..7eb6c18 100644
--- a/gui/text.cpp
+++ b/gui/text.cpp
@@ -26,116 +26,119 @@
 #include "objects.hpp"
 
 GUIText::GUIText(xml_node<>* node)
-    : Conditional(node)
+	: Conditional(node)
 {
-    xml_attribute<>* attr;
-    xml_node<>* child;
+	xml_attribute<>* attr;
+	xml_node<>* child;
 
-    mFont = NULL;
-    mIsStatic = 1;
-    mVarChanged = 0;
-    mFontHeight = 0;
+	mFont = NULL;
+	mIsStatic = 1;
+	mVarChanged = 0;
+	mFontHeight = 0;
 	maxWidth = 0;
 	charSkip = 0;
 	isHighlighted = false;
 	hasHighlightColor = false;
 
-    if (!node)      return;
+	if (!node)
+		return;
 
-    // Initialize color to solid black
-    memset(&mColor, 0, sizeof(COLOR));
-    mColor.alpha = 255;
+	// Initialize color to solid black
+	memset(&mColor, 0, sizeof(COLOR));
+	mColor.alpha = 255;
 	memset(&mHighlightColor, 0, sizeof(COLOR));
-    mHighlightColor.alpha = 255;
+	mHighlightColor.alpha = 255;
 
-    attr = node->first_attribute("color");
-    if (attr)
-    {
-        std::string color = attr->value();
-        ConvertStrToColor(color, &mColor);
-    }
+	attr = node->first_attribute("color");
+	if (attr)
+	{
+		std::string color = attr->value();
+		ConvertStrToColor(color, &mColor);
+	}
 	attr = node->first_attribute("highlightcolor");
-    if (attr)
-    {
-        std::string color = attr->value();
+	if (attr)
+	{
+		std::string color = attr->value();
 		ConvertStrToColor(color, &mHighlightColor);
 		hasHighlightColor = true;
-    }
+	}
 
-    // Load the font, and possibly override the color
-    child = node->first_node("font");
-    if (child)
-    {
-        attr = child->first_attribute("resource");
-        if (attr)
-            mFont = PageManager::FindResource(attr->value());
+	// Load the font, and possibly override the color
+	child = node->first_node("font");
+	if (child)
+	{
+		attr = child->first_attribute("resource");
+		if (attr)
+			mFont = PageManager::FindResource(attr->value());
 
-        attr = child->first_attribute("color");
-        if (attr)
-        {
-            std::string color = attr->value();
-            ConvertStrToColor(color, &mColor);
-        }
+		attr = child->first_attribute("color");
+		if (attr)
+		{
+			std::string color = attr->value();
+			ConvertStrToColor(color, &mColor);
+		}
 
 		attr = child->first_attribute("highlightcolor");
-        if (attr)
-        {
-            std::string color = attr->value();
+		if (attr)
+		{
+			std::string color = attr->value();
 			ConvertStrToColor(color, &mHighlightColor);
 			hasHighlightColor = true;
-        }
-    }
+		}
+	}
 
-    // Load the placement
-    LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
+	// Load the placement
+	LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
 
-    child = node->first_node("text");
-    if (child)  mText = child->value();
+	child = node->first_node("text");
+	if (child)  mText = child->value();
 
-    // Simple way to check for static state
-    mLastValue = parseText();
-    if (mLastValue != mText)   mIsStatic = 0;
+	// Simple way to check for static state
+	mLastValue = parseText();
+	if (mLastValue != mText)   mIsStatic = 0;
 
-    gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL);
-    return;
+	gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL);
+	return;
 }
 
 int GUIText::Render(void)
 {
-    if (!isConditionTrue())     return 0;
+	if (!isConditionTrue())
+		return 0;
 
-    void* fontResource = NULL;
+	void* fontResource = NULL;
 	string displayValue;
 
-    if (mFont)  fontResource = mFont->GetResource();
+	if (mFont)
+		fontResource = mFont->GetResource();
 
-    mLastValue = parseText();
+	mLastValue = parseText();
 	displayValue = mLastValue;
 
 	if (charSkip)
 		displayValue.erase(0, charSkip);
 
-    mVarChanged = 0;
+	mVarChanged = 0;
 
-    int x = mRenderX, y = mRenderY;
-    int width = gr_measureEx(displayValue.c_str(), fontResource);
+	int x = mRenderX, y = mRenderY;
+	int width = gr_measureEx(displayValue.c_str(), fontResource);
 
-    if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
-    {
-        if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY)
-            x -= (width / 2);
-        else
-            x -= width;
-    }
-    if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
-    {
-        if (mPlacement == CENTER)
-            y -= (mFontHeight / 2);
-        else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT)
-            y -= mFontHeight;
-    }
+	if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
+	{
+		if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY)
+			x -= (width / 2);
+		else
+			x -= width;
+	}
+	if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
+	{
+		if (mPlacement == CENTER)
+			y -= (mFontHeight / 2);
+		else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT)
+			y -= mFontHeight;
+	}
 
-    if (hasHighlightColor && isHighlighted)
+	if (hasHighlightColor && isHighlighted)
 		gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
 	else
 		gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
@@ -144,82 +147,85 @@
 		gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x);
 	else
 		gr_textEx(x, y, displayValue.c_str(), fontResource);
-    return 0;
+	return 0;
 }
 
 int GUIText::Update(void)
 {
-    if (!isConditionTrue())     return 0;
+	if (!isConditionTrue())
+		return 0;
 
-    static int updateCounter = 3;
+	static int updateCounter = 3;
 
-    // This hack just makes sure we update at least once a minute for things like clock and battery
-    if (updateCounter)  updateCounter--;
-    else
-    {
-        mVarChanged = 1;
-        updateCounter = 3;
-    }
+	// This hack just makes sure we update at least once a minute for things like clock and battery
+	if (updateCounter)  updateCounter--;
+	else
+	{
+		mVarChanged = 1;
+		updateCounter = 3;
+	}
 
-    if (mIsStatic || !mVarChanged)      return 0;
+	if (mIsStatic || !mVarChanged)
+		return 0;
 
-    std::string newValue = parseText();
-    if (mLastValue == newValue)
+	std::string newValue = parseText();
+	if (mLastValue == newValue)
 		return 0;
 	else
 		mLastValue = newValue;
-    return 2;
+	return 2;
 }
 
 int GUIText::GetCurrentBounds(int& w, int& h)
 {
-    void* fontResource = NULL;
+	void* fontResource = NULL;
 
-    if (mFont)  fontResource = mFont->GetResource();
+	if (mFont)
+		fontResource = mFont->GetResource();
 
-    h = mFontHeight;
+	h = mFontHeight;
 	mLastValue = parseText();
-    w = gr_measureEx(mLastValue.c_str(), fontResource);
-    return 0;
+	w = gr_measureEx(mLastValue.c_str(), fontResource);
+	return 0;
 }
 
 std::string GUIText::parseText(void)
 {
-    static int counter = 0;
-    std::string str = mText;
-    size_t pos = 0;
-    size_t next = 0, end = 0;
+	static int counter = 0;
+	std::string str = mText;
+	size_t pos = 0;
+	size_t next = 0, end = 0;
 
-    while (1)
-    {
-        next = str.find('%', pos);
-        if (next == std::string::npos)      return str;
-        end = str.find('%', next + 1);
-        if (end == std::string::npos)       return str;
+	while (1)
+	{
+		next = str.find('%', pos);
+		if (next == std::string::npos) return str;
+		end = str.find('%', next + 1);
+		if (end == std::string::npos) return str;
 
-        // We have a block of data
-        std::string var = str.substr(next + 1, (end - next) - 1);
-        str.erase(next, (end - next) + 1);
+		// We have a block of data
+		std::string var = str.substr(next + 1, (end - next) - 1);
+		str.erase(next, (end - next) + 1);
 
-        if (next + 1 == end)
-        {
-            str.insert(next, 1, '%');
-        }
-        else
-        {
-            std::string value;
-            if (DataManager::GetValue(var, value) == 0)
-                str.insert(next, value);
-        }
+		if (next + 1 == end)
+		{
+			str.insert(next, 1, '%');
+		}
+		else
+		{
+			std::string value;
+			if (DataManager::GetValue(var, value) == 0)
+				str.insert(next, value);
+		}
 
-        pos = next + 1;
-    }
+		pos = next + 1;
+	}
 }
 
 int GUIText::NotifyVarChange(std::string varName, std::string value)
 {
-    mVarChanged = 1;
-    return 0;
+	mVarChanged = 1;
+	return 0;
 }
 
 int GUIText::SetMaxWidth(unsigned width)
diff --git a/partition.cpp b/partition.cpp
index dc71bb9..e02def0 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -1062,7 +1062,7 @@
 
 	gui_print("Wiping %s\n", Backup_Display_Name.c_str());
 	TWFunc::removeDir(Mount_Point + "/.android_secure/", true);
-    return true;
+	return true;
 }
 
 bool TWPartition::Backup(string backup_folder) {
@@ -1361,31 +1361,31 @@
 
 	gui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str());
 
-    mtd_scan_partitions();
-    const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
-    if (mtd == NULL) {
-        LOGERR("No mtd partition named '%s'", MTD_Name.c_str());
-        return false;
-    }
+	mtd_scan_partitions();
+	const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
+	if (mtd == NULL) {
+		LOGERR("No mtd partition named '%s'", MTD_Name.c_str());
+		return false;
+	}
 
-    MtdWriteContext* ctx = mtd_write_partition(mtd);
-    if (ctx == NULL) {
-        LOGERR("Can't write '%s', failed to format.", MTD_Name.c_str());
-        return false;
-    }
-    if (mtd_erase_blocks(ctx, -1) == -1) {
-        mtd_write_close(ctx);
-        LOGERR("Failed to format '%s'", MTD_Name.c_str());
-        return false;
-    }
-    if (mtd_write_close(ctx) != 0) {
-        LOGERR("Failed to close '%s'", MTD_Name.c_str());
-        return false;
-    }
+	MtdWriteContext* ctx = mtd_write_partition(mtd);
+	if (ctx == NULL) {
+		LOGERR("Can't write '%s', failed to format.", MTD_Name.c_str());
+		return false;
+	}
+	if (mtd_erase_blocks(ctx, -1) == -1) {
+		mtd_write_close(ctx);
+		LOGERR("Failed to format '%s'", MTD_Name.c_str());
+		return false;
+	}
+	if (mtd_write_close(ctx) != 0) {
+		LOGERR("Failed to close '%s'", MTD_Name.c_str());
+		return false;
+	}
 	Current_File_System = "yaffs2";
 	Recreate_AndSec_Folder();
 	gui_print("Done.\n");
-    return true;
+	return true;
 }
 
 bool TWPartition::Wipe_RMRF() {
@@ -1415,7 +1415,7 @@
 			if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)   continue;
 			// The media folder is the "internal sdcard"
 			// The .layout_version file is responsible for determining whether 4.2 decides up upgrade
-			//    the media folder for multi-user.
+			// the media folder for multi-user.
 			if (strcmp(de->d_name, "media") == 0 || strcmp(de->d_name, ".layout_version") == 0)   continue;
 			
 			dir = "/data/";
@@ -1560,7 +1560,7 @@
 	} else {
 		gui_print("Wiping %s...\n", Display_Name.c_str());
 		if (!Wipe(Restore_File_System))
-		    return false;
+			return false;
 	}
 	TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Backup_Display_Name, "Restoring");
 	gui_print("Restoring %s...\n", Backup_Display_Name.c_str());
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 71e5e34..77cf37e 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -1104,14 +1104,14 @@
 		}
 	}
 	TWPartition* sdext = Find_Partition_By_Path("/sd-ext");
-	if (sdext != NULL) {
-		if (sdext->Is_Present && sdext->Mount(false)) {
-			if (stat("/sd-ext/dalvik-cache", &st) == 0) {
-				TWFunc::removeDir("/sd-ext/dalvik-cache", false);
-        	    		gui_print("Cleaned: /sd-ext/dalvik-cache...\n");
-			}
+	if (sdext && sdext->Is_Present && sdext->Mount(false))
+	{
+		if (stat("/sd-ext/dalvik-cache", &st) == 0)
+		{
+			TWFunc::removeDir("/sd-ext/dalvik-cache", false);
+	   	    gui_print("Cleaned: /sd-ext/dalvik-cache...\n");
 		}
-        }
+	}
 	gui_print("-- Dalvik Cache Directories Wipe Complete!\n\n");
 	return true;
 }
@@ -1893,4 +1893,4 @@
 		}
 	}
 	fclose(fp);
-}
\ No newline at end of file
+}
diff --git a/twbootloader.cpp b/twbootloader.cpp
index 826ceca..d0e49e0 100644
--- a/twbootloader.cpp
+++ b/twbootloader.cpp
@@ -33,33 +33,35 @@
 static int set_bootloader_message_block(const struct bootloader_message *in, const TWPartition* Partition);
 
 int get_bootloader_message(struct bootloader_message *out) {
-    TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
-    if (Part == NULL) {
-      //LOGE("Cannot load volume /misc!\n");
-      return -1;
-    }
-    if (Part->Current_File_System == "mtd") {
-        return get_bootloader_message_mtd(out, Part);
-    } else if (Part->Current_File_System == "emmc") {
-        return get_bootloader_message_block(out, Part);
-    }
-    LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
-    return -1;
+	TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
+	if (Part == NULL) {
+	  //LOGE("Cannot load volume /misc!\n");
+	  return -1;
+	}
+
+	if (Part->Current_File_System == "mtd")
+		return get_bootloader_message_mtd(out, Part);
+	else if (Part->Current_File_System == "emmc")
+		return get_bootloader_message_block(out, Part);
+
+	LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
+	return -1;
 }
 
 int set_bootloader_message(const struct bootloader_message *in) {
-    TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
-    if (Part == NULL) {
-      //LOGE("Cannot load volume /misc!\n");
-      return -1;
-    }
-    if (Part->Current_File_System == "mtd") {
-        return set_bootloader_message_mtd(in, Part);
-    } else if (Part->Current_File_System == "emmc") {
-        return set_bootloader_message_block(in, Part);
-    }
-    LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
-    return -1;
+	TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
+	if (Part == NULL) {
+	  //LOGE("Cannot load volume /misc!\n");
+	  return -1;
+	}
+
+	if (Part->Current_File_System == "mtd")
+		return set_bootloader_message_mtd(in, Part);
+	else if (Part->Current_File_System == "emmc")
+		return set_bootloader_message_block(in, Part);
+
+	LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
+	return -1;
 }
 
 // ------------------------------
@@ -71,134 +73,141 @@
 
 static int get_bootloader_message_mtd(struct bootloader_message *out,
                                       const TWPartition* Partition) {
-    size_t write_size;
-    mtd_scan_partitions();
-    const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
-    if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
-        LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
-        return -1;
-    }
+	size_t write_size;
+	mtd_scan_partitions();
+	const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
+	if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
+		LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
+		return -1;
+	}
 
-    MtdReadContext *read = mtd_read_partition(part);
-    if (read == NULL) {
-        LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-        return -1;
-    }
+	MtdReadContext *read = mtd_read_partition(part);
+	if (read == NULL) {
+		LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+		return -1;
+	}
 
-    const ssize_t size = write_size * MISC_PAGES;
-    char data[size];
-    ssize_t r = mtd_read_data(read, data, size);
-    if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-    mtd_read_close(read);
-    if (r != size) return -1;
+	const ssize_t size = write_size * MISC_PAGES;
+	char data[size];
+	ssize_t r = mtd_read_data(read, data, size);
+	if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+	mtd_read_close(read);
+	if (r != size) return -1;
 
-    memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out));
-    return 0;
+	memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out));
+	return 0;
 }
 static int set_bootloader_message_mtd(const struct bootloader_message *in,
                                       const TWPartition* Partition) {
-    size_t write_size;
-    mtd_scan_partitions();
-    const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
-    if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
-        LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
-        return -1;
-    }
+	size_t write_size;
+	mtd_scan_partitions();
+	const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
+	if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
+		LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
+		return -1;
+	}
 
-    MtdReadContext *read = mtd_read_partition(part);
-    if (read == NULL) {
-        LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-        return -1;
-    }
+	MtdReadContext *read = mtd_read_partition(part);
+	if (read == NULL) {
+		LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+		return -1;
+	}
 
-    ssize_t size = write_size * MISC_PAGES;
-    char data[size];
-    ssize_t r = mtd_read_data(read, data, size);
-    if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-    mtd_read_close(read);
-    if (r != size) return -1;
+	ssize_t size = write_size * MISC_PAGES;
+	char data[size];
+	ssize_t r = mtd_read_data(read, data, size);
+	if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+	mtd_read_close(read);
+	if (r != size) return -1;
 
-    memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));
+	memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));
 
-    MtdWriteContext *write = mtd_write_partition(part);
-    if (write == NULL) {
-        LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-        return -1;
-    }
-    if (mtd_write_data(write, data, size) != size) {
-        LOGE("Can't write %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-        mtd_write_close(write);
-        return -1;
-    }
-    if (mtd_write_close(write)) {
-        LOGE("Can't finish %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
-        return -1;
-    }
+	MtdWriteContext *write = mtd_write_partition(part);
+	if (write == NULL) {
+		LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+		return -1;
+	}
+	if (mtd_write_data(write, data, size) != size) {
+		LOGE("Can't write %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+		mtd_write_close(write);
+		return -1;
+	}
+	if (mtd_write_close(write)) {
+		LOGE("Can't finish %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
+		return -1;
+	}
 
-    LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
-    return 0;
+	LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
+	return 0;
 }
 
-
 // ------------------------------------
 // for misc partitions on block devices
 // ------------------------------------
 
 static void wait_for_device(const char* fn) {
-    int tries = 0;
-    int ret;
-    struct stat buf;
-    do {
-        ++tries;
-        ret = stat(fn, &buf);
-        if (ret) {
-            printf("stat %s try %d: %s\n", fn, tries, strerror(errno));
-            sleep(1);
-        }
-    } while (ret && tries < 10);
-    if (ret) {
-        printf("failed to stat %s\n", fn);
-    }
+	int tries = 0;
+	int ret;
+	struct stat buf;
+
+	do {
+		++tries;
+		ret = stat(fn, &buf);
+		if (ret) {
+			printf("stat %s try %d: %s\n", fn, tries, strerror(errno));
+			sleep(1);
+		}
+	} while (ret && tries < 10);
+
+	if (ret)
+		printf("failed to stat %s\n", fn);
 }
 
 static int get_bootloader_message_block(struct bootloader_message *out,
                                         const TWPartition* Partition) {
-    wait_for_device(Partition->Actual_Block_Device.c_str());
-    FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "rb");
-    if (f == NULL) {
-        LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    struct bootloader_message temp;
-    int count = fread(&temp, sizeof(temp), 1, f);
-    if (count != 1) {
-        LOGE("Failed reading %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    if (fclose(f) != 0) {
-        LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    memcpy(out, &temp, sizeof(temp));
-    return 0;
+	wait_for_device(Partition->Actual_Block_Device.c_str());
+
+	FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "rb");
+	if (f == NULL) {
+		LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+
+	struct bootloader_message temp;
+	int count = fread(&temp, sizeof(temp), 1, f);
+	if (count != 1) {
+		LOGE("Failed reading %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+
+	if (fclose(f) != 0) {
+		LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+
+	memcpy(out, &temp, sizeof(temp));
+	return 0;
 }
 
 static int set_bootloader_message_block(const struct bootloader_message *in,
                                         const TWPartition* Partition) {
-    wait_for_device(Partition->Actual_Block_Device.c_str());
-    FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "wb");
-    if (f == NULL) {
-        LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    int count = fwrite(in, sizeof(*in), 1, f);
-    if (count != 1) {
-        LOGE("Failed writing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    if (fclose(f) != 0) {
-        LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
-        return -1;
-    }
-    return 0;
+	wait_for_device(Partition->Actual_Block_Device.c_str());
+
+	FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "wb");
+	if (f == NULL) {
+		LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+
+	int count = fwrite(in, sizeof(*in), 1, f);
+	if (count != 1) {
+		LOGE("Failed writing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+
+	if (fclose(f) != 0) {
+		LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
+		return -1;
+	}
+	return 0;
 }
diff --git a/twinstall.cpp b/twinstall.cpp
index e7d23ec..041c78d 100644
--- a/twinstall.cpp
+++ b/twinstall.cpp
@@ -87,37 +87,37 @@
 	child_data = fdopen(pipe_fd[0], "r");
 	while (fgets(buffer, sizeof(buffer), child_data) != NULL) {
 		char* command = strtok(buffer, " \n");
-        if (command == NULL) {
-            continue;
-        } else if (strcmp(command, "progress") == 0) {
-            char* fraction_char = strtok(NULL, " \n");
-            char* seconds_char = strtok(NULL, " \n");
+		if (command == NULL) {
+			continue;
+		} else if (strcmp(command, "progress") == 0) {
+			char* fraction_char = strtok(NULL, " \n");
+			char* seconds_char = strtok(NULL, " \n");
 
-            float fraction_float = strtof(fraction_char, NULL);
-            int seconds_float = strtol(seconds_char, NULL, 10);
+			float fraction_float = strtof(fraction_char, NULL);
+			int seconds_float = strtol(seconds_char, NULL, 10);
 
-            if (zip_verify)
+			if (zip_verify)
 				DataManager::ShowProgress(fraction_float * (1 - VERIFICATION_PROGRESS_FRACTION), seconds_float);
 			else
 				DataManager::ShowProgress(fraction_float, seconds_float);
-        } else if (strcmp(command, "set_progress") == 0) {
-            char* fraction_char = strtok(NULL, " \n");
-            float fraction_float = strtof(fraction_char, NULL);
-            DataManager::SetProgress(fraction_float);
-        } else if (strcmp(command, "ui_print") == 0) {
-            char* display_value = strtok(NULL, "\n");
-            if (display_value) {
-                gui_print("%s", display_value);
-            } else {
-                gui_print("\n");
-            }
-        } else if (strcmp(command, "wipe_cache") == 0) {
-            *wipe_cache = 1;
-        } else if (strcmp(command, "clear_display") == 0) {
-            // Do nothing, not supported by TWRP
-        } else {
-            LOGERR("unknown command [%s]\n", command);
-        }
+		} else if (strcmp(command, "set_progress") == 0) {
+			char* fraction_char = strtok(NULL, " \n");
+			float fraction_float = strtof(fraction_char, NULL);
+			DataManager::SetProgress(fraction_float);
+		} else if (strcmp(command, "ui_print") == 0) {
+			char* display_value = strtok(NULL, "\n");
+			if (display_value) {
+				gui_print("%s", display_value);
+			} else {
+				gui_print("\n");
+			}
+		} else if (strcmp(command, "wipe_cache") == 0) {
+			*wipe_cache = 1;
+		} else if (strcmp(command, "clear_display") == 0) {
+			// Do nothing, not supported by TWRP
+		} else {
+			LOGERR("unknown command [%s]\n", command);
+		}
 	}
 	fclose(child_data);
 
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 29c70a5..1d2d632 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -424,15 +424,17 @@
 }
 
 int TWFunc::read_file(string fn, string& results) {
-        ifstream file;
-        file.open(fn.c_str(), ios::in);
-        if (file.is_open()) {
-                file >> results;
-                file.close();
-                return 0;
+	ifstream file;
+	file.open(fn.c_str(), ios::in);
+
+	if (file.is_open()) {
+		file >> results;
+		file.close();
+		return 0;
 	}
-        LOGINFO("Cannot find file %s\n", fn.c_str());
-        return -1;
+
+	LOGINFO("Cannot find file %s\n", fn.c_str());
+	return -1;
 }
 
 int TWFunc::read_file(string fn, vector<string>& results) {
@@ -498,7 +500,7 @@
 	return temp;
 }
 
- int TWFunc::drop_caches(void) {
+int TWFunc::drop_caches(void) {
 	string file = "/proc/sys/vm/drop_caches";
 	string value = "3";
 	if (write_file(file, value) != 0)
@@ -714,7 +716,7 @@
 	string::size_type i = 0;
 	int firstbyte = 0, secondbyte = 0;
 	char header[3];
-        
+
 	ifstream f;
 	f.open(fn.c_str(), ios::in | ios::binary);
 	f.get(header, 3);
@@ -722,13 +724,12 @@
 	firstbyte = header[i] & 0xff;
 	secondbyte = header[++i] & 0xff;
 
-	if (firstbyte == 0x1f && secondbyte == 0x8b) {
+	if (firstbyte == 0x1f && secondbyte == 0x8b)
 		return 1; // Compressed
-	} else if (firstbyte == 0x4f && secondbyte == 0x41) {
+	else if (firstbyte == 0x4f && secondbyte == 0x41)
 		return 2; // Encrypted
-	} else {
+	else
 		return 0; // Unknown
-	}
 
 	return 0;
 }
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index 9f66621..8531c09 100644
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -8,12 +8,12 @@
 
 typedef enum
 {
-    rb_current = 0,
-    rb_system,
-    rb_recovery,
-    rb_poweroff,
-    rb_bootloader,     // May also be fastboot
-    rb_download,
+	rb_current = 0,
+	rb_system,
+	rb_recovery,
+	rb_poweroff,
+	rb_bootloader,     // May also be fastboot
+	rb_download,
 } RebootCommand;
 
 // Partition class
diff --git a/twrp.cpp b/twrp.cpp
index 04851aa..2c2aed4 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -152,7 +152,7 @@
 		}
 	}
 
-    char twrp_booted[PROPERTY_VALUE_MAX];
+	char twrp_booted[PROPERTY_VALUE_MAX];
 	property_get("ro.twrp.boot", twrp_booted, "0");
 	if (strcmp(twrp_booted, "0") == 0) {
 		property_list(Print_Prop, NULL);
@@ -242,10 +242,10 @@
 		PartitionManager.UnMount_By_Path("/system", false);
 	}
 
-    // Reboot
+	// Reboot
 	TWFunc::Update_Intent_File(Reboot_Value);
-    TWFunc::Update_Log_File();
-    gui_print("Rebooting...\n");
+	TWFunc::Update_Log_File();
+	gui_print("Rebooting...\n");
 	string Reboot_Arg;
 	DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
 	if (Reboot_Arg == "recovery")
@@ -260,9 +260,9 @@
 		TWFunc::tw_reboot(rb_system);
 
 #ifdef ANDROID_RB_RESTART
-    android_reboot(ANDROID_RB_RESTART, 0, 0);
+	android_reboot(ANDROID_RB_RESTART, 0, 0);
 #else
 	reboot(RB_AUTOBOOT);
 #endif
-    return 0;
+	return 0;
 }
diff --git a/twrpDigest.cpp b/twrpDigest.cpp
index 663d085..ce3d87c 100644
--- a/twrpDigest.cpp
+++ b/twrpDigest.cpp
@@ -16,10 +16,12 @@
 	along with TWRP.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-extern "C" {
+extern "C"
+{
 	#include "digest/md5.h"
 	#include "libcrecovery/common.h"
 }
+
 #include <vector>
 #include <string>
 #include <sstream>
diff --git a/twrpDigest.hpp b/twrpDigest.hpp
index 395c0ae..237e580 100644
--- a/twrpDigest.hpp
+++ b/twrpDigest.hpp
@@ -18,18 +18,21 @@
 extern "C" {
 	#include "digest/md5.h"
 }
+
 using namespace std;
 
-class twrpDigest {
-	public:
-                void setfn(string fn);
-                void setdir(string dir);
-		int computeMD5(void);
-		int verify_md5digest(void);
-		int write_md5digest(void);
-	private:
-		int read_md5digest(void);
-		string md5fn;
-		string line;
-		unsigned char md5sum[MD5LENGTH];
+class twrpDigest
+{
+public:
+	void setfn(string fn);
+	void setdir(string dir);
+	int computeMD5(void);
+	int verify_md5digest(void);
+	int write_md5digest(void);
+
+private:
+	int read_md5digest(void);
+	string md5fn;
+	string line;
+	unsigned char md5sum[MD5LENGTH];
 };
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 59d75d0..5964f2f 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -1297,7 +1297,7 @@
 
 unsigned long long twrpTar::uncompressedSize() {
 	int type = 0;
-        unsigned long long total_size = 0;
+	unsigned long long total_size = 0;
 	string Tar, Command, result;
 	vector<string> split;
 
diff --git a/twrpTar.hpp b/twrpTar.hpp
index e270d90..88eedb5 100644
--- a/twrpTar.hpp
+++ b/twrpTar.hpp
@@ -17,7 +17,7 @@
 */
 
 extern "C" {
-        #include "libtar/libtar.h"
+	#include "libtar/libtar.h"
 }
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -41,59 +41,60 @@
 };
 
 class twrpTar {
-	public:
-		twrpTar();
-		virtual ~twrpTar();
-		int createTarFork();
-		int extractTarFork();
-		int splitArchiveFork();
-		void setexcl(string exclude);
-		void setfn(string fn);
-		void setdir(string dir);
-		unsigned long long uncompressedSize();
-		
-	public:
-		int use_encryption;
-		int userdata_encryption;
-		int use_compression;
-		int split_archives;
-		int has_data_media;
-		string backup_name;
+public:
+	twrpTar();
+	virtual ~twrpTar();
+	int createTarFork();
+	int extractTarFork();
+	int splitArchiveFork();
+	void setexcl(string exclude);
+	void setfn(string fn);
+	void setdir(string dir);
+	unsigned long long uncompressedSize();
+	
+public:
+	int use_encryption;
+	int userdata_encryption;
+	int use_compression;
+	int split_archives;
+	int has_data_media;
+	string backup_name;
 
-	private:
-		int extract();
-		int addFilesToExistingTar(vector <string> files, string tarFile);
-		int createTar();
-		int addFile(string fn, bool include_root);
-		int entryExists(string entry);
-		int closeTar();
-		int create();
-		int Split_Archive();
-		int removeEOT(string tarFile);
-		int extractTar();
-		int tarDirs(bool include_root);
-		int Generate_Multiple_Archives(string Path);
-		string Strip_Root_Dir(string Path);
-		int openTar();
-		int Archive_File_Count;
-		int Archive_Current_Type;
-		unsigned long long Archive_Current_Size;
-		TAR *t;
-		int fd;
-		pid_t pigz_pid;
-		pid_t oaes_pid;
+private:
+	int extract();
+	int addFilesToExistingTar(vector <string> files, string tarFile);
+	int createTar();
+	int addFile(string fn, bool include_root);
+	int entryExists(string entry);
+	int closeTar();
+	int create();
+	int Split_Archive();
+	int removeEOT(string tarFile);
+	int extractTar();
+	int tarDirs(bool include_root);
+	int Generate_Multiple_Archives(string Path);
+	string Strip_Root_Dir(string Path);
+	int openTar();
+	int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
+	static void* createList(void *cookie);
+	static void* extractMulti(void *cookie);
+	int tarList(bool include_root, std::vector<TarListStruct> *TarList, unsigned thread_id);
 
-		string tardir;
-		string tarfn;
-		string basefn;
-		string tarexclude;
+	int Archive_File_Count;
+	int Archive_Current_Type;
+	unsigned long long Archive_Current_Size;
+	TAR *t;
+	int fd;
+	pid_t pigz_pid;
+	pid_t oaes_pid;
 
-		vector<string> split;
+	string tardir;
+	string tarfn;
+	string basefn;
+	string tarexclude;
 
-		int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
-		static void* createList(void *cookie);
-		static void* extractMulti(void *cookie);
-		int tarList(bool include_root, std::vector<TarListStruct> *TarList, unsigned thread_id);
-		std::vector<TarListStruct> *ItemList;
-		int thread_id;
+	vector<string> split;
+
+	std::vector<TarListStruct> *ItemList;
+	int thread_id;
 }; 
