refactored the algorithms to algorithms.c