preferences: Implement preferences class and tests for it