Bug 958782 - 2.b/3: implementation.
Bug 958782 - 2.c/3: remove unused headers and sort.
Bug 958782 - 3/3: fix test cases.