initial algorithm without message passing