clean up err handling, reorg a bit