core: fix crash when buffer is closed during execution of multiple commands (closes #27)