Final patch with more edge cases per Darin and Ollie's review.