Fix compile errors, begin bugfixing