not the most elegant, but it works!