fixed invalid close and asserts