moved optimization code to seperate algorithm class