fixes most of the bugs