worte algorithm in mainfile, not currently working