Moved back some of the logic