fixes various critical bugs