working in Bash -- code of Rumen and Ivan