Refactoring libmarpa