Fixed several bugs in build system