Fix discard handling and test cases