bug fix, start of refactoring