synch
completed algorithm, properly now