a bit of refactoring and adding some tests for the life cycle of a Prolog engine