ixed some misplaced statements which caused the algorithms to fail