works now, will need some cleanup later