Fixed a few logic bugs, seems to be working now.