Move algorithm into separate function