rewrote API factory into a proper object