Make my script more generic

https://gist.github.com/k-saka/cd3a69c1002a80c0af05