Refactored object generation code and add headers