fixed bugs introduced when refactoring and not testing