Fixed error on exit, added on_close hook