Clean up code & security fixes

More meaningful variable names, better names, clearer code, prepared SQL
statements...the list goes on.