Refactor to have stateless API