Implemented jjn1056's idea