added prefs, did some refactoring