Refactor API builder