I believe this code should be isolated in a function