Massive refactoring. Logic moved to ABG. REPL generalized. Tests need to be expanded