I tested this with my specs, and it seems it works. I tried to fit all the edge cases into the spec. Thanks.