Added example of replace vars. Better exception handling