Refactored sinproc shutdown code (fixes #31)

Signed-off-by: Paul Colomiets <paul@colomiets.name>