Code refactor, bugfixes, better settings management