Cleaned up the code a little. Now uses a common settings function.