Refactored search by breaking the weight and pagination sections into separate functions