Refactor functions to support common interface

Initial refactoring of gmres