This works but not at all optimised