Refactored completion engine & fixed some failing unit tests.