updated logic and output