Fix a bug (hopefully)
Add tests