refactor script execution to work on one message at a time