Seperated the folding algorithm into its own class