Re-organizing types and adding applicative/functor instances