moved algorithm logic out of Canvas.java into Algorithm.java