Support for order history

Various bug fixes