working, but needs cleanup and error checking