removed unnecessary checks in solution 2