Code improvements

This brings it mostly inline with JSHint. Removed a lot of garbage.
Consistent indentation.