fixes and tests for similar cases to #1015