refactor so that api uses Applicatives rather than Monads