some code cleanup with help from jslint