Fixed some critical bugs