added graceful stopping