More cleanup and better service state detection