Code refactored, fixed bug in settings mechanism