Further fixed javascript logic