a* rewrite