Pretty functional version
Most error handling is there (but see issues for more stuff to do)