added some commenting, made some tweaks