Move units tests, start some refactoring, fix compilation problems due to merge