Used do notation throughout; used more idiomatic I/O code