Cleaned up some code and stuff

* Cleaned up some unused code.
* Also fixed a couple of streams that were never closed