Fixed bug where fd(0) was getting closed by accident - fixes #11

Also added more trace logging