changed some of the logic