Implemented closing of streams and updating relations