Move restrictions code into a module for use elsewhere. (#489)