bug fixed with tests