changing the logic and adding a write-output