Code cleaned up and added final output