Fix bugs in service starting/stopping.