If you try to implement you own version of A* search is why you haven't understand it. Please check it out again and come back to the Wikipedia to copy the pseudocode.