fixed bug in mysql data dump, cleaned up code