Cleaned up algorithms