refined bash script