Implemenation of A*