trying to fix javascript scope