spaghetti code correction.