added code to run as an external script