Improve order handling

Fixes #732