Renamed and optimized code
Added variable for default algorithm