fixed out-dated references
fixed missing calls to close on open files - thanks for catching these @jrrideout