Improve episode_data code in rail and javascript