updated logic with PWs