a* algorithm added. misc refactoring.