Two equal implementation plus a bunch of refactoring