Moved script lines to if-main code block