Added support for settings, more refactoring