Fixed some bugs with logic.