Adapted for older Haskell platform.