Fixed some bugs in building system