Fixed all four algorithms. Documentation still needed.