Some code cleanup and an attempt at fixing the build system