functional but error checking needs a lot of work