cleaned up code with tips from JSHint