Small refactorings (similar to pappz' implementation)
Moved preferences to separate package