Acknowledgement: This commit is a result of core3 review by Marek.
This is a big commit and probably incomplete. Tests will follow.