Issue #40: moved some code around, tuned public/private access