Added initial directory change and moved variables to arguments