Improving thread safety and interactions on sleep/wake. Plus minor improvements to the main thread (CPController).