refactors api module to use methods instead of inline code in the constructor.