moved logic over into a function.