bug fixes, commenting, and code clean up