Fix bug from last commit,
Add tests