Tidy up MySQL code a little