cleanup code

basic cleanup of file descriptors