Cleaned up sql and map code to read a bit easier