fix up and test edge cases

also, like, handle signals.

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