Code cleanup and optimization

- Changed indentation to 4 spaces
- Fixed missing semicolons
- Fixed common javascript errors as per JSLint / JSHint (function declaration in loops, combined multiple vars, ...)
- Introduced "use strict"
- Removed unused function parameters