made BuildMode and fixed some bugs