Several bugfixes
- Removal of deprecated mysql_escape_string in favor of esc_sql
- Addition of braces to improve code readability