well it's up to you to properly test different cases and to adapt the code :) You know, I'm writing code samples in github comments to give the idea, you should not consider these as "the proven perfect solution".