Cleaned up SQL a bit