improved bash script