Implement governor middleware

Still needs lots of review and testing!