Restructured code - removed redundancy