Cleaned up algorithms.