Some comments, code cleanup, and fixing var declarations