Restructure, define new function, to remove gotos.