Refactored API code into dataset module