first set of changes from Brent Fulgham, a bunch more coming in the C code.