Optimizations for MySQL

Made it only run status() when the query fails, that way it doesn't run it every time.
Fixed errors in pull request