updated, but may have to rewrite