fix process management to ensure proper shutdown