updated prolog implementation