fixed many of the bugs