Closes #652 (closed).
Also contains some restructuring of the visibility code.
mentioned in commit 101c20f8
merged