Move more things to functions. Reduced cide size by 200+ lines