Began moving duplicate code to functions file