Added settings support, refactoring