Refactor and remove whitespace from the page javascript