refactor with passing tests
removed unused code
 initial pass at simple but dangerous guards
commented out debug logging