Fix stupid JSHint error and rearragned some code to make it clearer