a whole bunch more type checking and such