start of solution for #24, far too slow though