build: refactor the object reduction code