Started refactoring, more to come...