Moved var statement on top of function