little bit cleaner javascript