Refactored connection closing, added errors on bad paths