restructured code for future maintainablity