Refactore setting of algorithm (not tested)