Refactoring to allow different backends.