Cleanup, split common code to base class.