change to use scope to create function