Fix JSHint warnings and improve code style