Added safety checks to bash script