Refactor algorithms to use base classes.