simpler and safer closing

Signed-off-by: Momchil Atanasov <m.momchil@gmail.com>