properly closing connection and stuff