Fixed a few bugs.
Initial refactoring done.
I think that it is safe to say that the refactoring is officially done.
Merge branch 'refactor' into develop
Merge branch 'develop'