some commenting, removed some magic numbers