rearrange some code, add some comments
change to tap output for tests