bug fix + tests