Message passing algorithm for 2D lattices