Moved anonymous function out of function