Major fixes to Material controller and sorting mechanism