fixes some critical bugs