Input streams

@jdillon yeah - maybe it is the right time to refactor this as well. my intention was to fix the places where streams were not closed (too bad that I needed someone to tell me). so let me just do it right now then.