Move repetitive code to shell script