Primary refactoring of Logic. Still requires more refactoring.