porting improvements discovered while working in C back to Haskell for 0.6.3