Cleaned up JS code around setting view.