Optimized some of the functions in helpers.js