Lots of help functions for A*