Restructured code for easier programming