works but could use some cleaning up