can you explain what this function does? does it belong here or could it go to a .js file?