removed duplicate code
moved algorithm delegate into its own file