removed some cruft from first attempt and played around with making it
more general