working algorithm, screenshots