Client side improvements

Several improvements. Maintainability, performance, logic... No adaptations for JSLint/JSHint yet.