Fix bug and move tests