Fixed some of the logic