Final a* implementation