shell script refactoring
resolved #34 / misc bug fixes