a whole bunch of fixes and some ugly conversion code