simple refactoring, mostly to eliminate do notation where it did not obfuscate the code too much
further refactoring - minor