Javascript - code clean up