Tidy up, added jquery map, improved sorting