Fix #291 - some bad refactoring