Fixing and tidying JS