Refactor the handling of algorithms