Moved variable declaration deeper in nesting to prevent it from being instantiated if not necessary