FIX: Many JSHint failures, some bugs due to variable scope.