many more edge case fixes