Reshaped Algorithm to module