cleaning up some alert() messages and fixing a sort bug in code