adding a little error handling, type variable genericization and more sophisticated parsing