The implementation follows for most part the PHP code but introduces an additional layer parameter with which the kind of places to be returned can be restricted. This replaces the hard-coded exclusion lists.
This uses the debug output facility meant for pretty HTML output to give us debugging output for the unit tests.