Refactor and add reset option.
Update tests.