Refactoring to use Pyramid