Refactored code to be slightly more readable
Added support for CustomField