simplified Javascript code