cleanups
applied commits 1cf5b12ae23d95fd9d09c8576672467ec65641b5 & c806b3f082045b7557f469d554da4233c254149a from CM source