added comments and removed debugging prints