Fixed incorrect javascript function