fixed some bugs in engine