Refactored api controller builder
Minor refactorings.