trying to fix javascript functionality