added gui, fixed algorithm