Seperate out functions and update / clean code.