Fixed issues in alg