Working on better javascript writing