Tidy some #includes and forward-declarations, and move the C binding code