fixed some critical bugs