inefficient, but working :)