Fixed some bugs

Fixed some logic bugs that were causing weird visual effects.