Ongoing commit, some refactoring