Cleaned the code, added some javadoc and changed snapXToGrid and snapYToGrid to snapToGrid