Phase class

Added a phase class, changed some systems to be more logical, fixed a
bug in the spawning algorithm.