Updated to be compatible with new minimally-sized enums, by deriving FromPrimitive on the relevant enums. This nicely cleaned up some of the code.