Make discardchanges more versatile. Fixes #54