Fixed logic, and learned to SQL. (derp)