started converting code to functions