Refine code, add new pyramid version for test, use mock instead of flexmock