Fixed some simple logic errors