cleaning code and adding tests