Restructured code to be more easily reusable