Move auxiliary functions out of main.js