Start refactor process. 1. Seperate functions out