Fix breaking build, and some code cleanup