Moving function to scope