Move some library functions out of JS and into Elm