Fixed closing file descriptors. Added some more debug info.