Moving functions and adding tests