Restructured code to remove errors.