Added code to better handle start/stop conditions