Moved some code in a function for future development