Implementation of A*