compactify
move more all IO into main