Refactoring, clean up and started to add settings support