Some refactoring to get rid of JSHint errors