refactoring / fixes for issues #140, #141, #146