move alg out to separate file