Altered code to properly switch between frames