Move layer map into traverseLayers

Also, change name of main recursion function to traverseLayers