removed bashisms and use $() instead if backticks