modified to the correct logic, working testbench