Lots of code cleanup, SQL injection prevention :)