it's the simplest way I could think of, and it should be working in each and every edge case I thought about. Do you have any other ideas or suggestions?