Refactored custom fields code