fixes bug in previous commit, adds tests