factor out ps7 code