factored preferences code. added error handling in setup activity.