bugfix and tiny optimization for callbacks from Haskell