Is it possible to make it into a single function that works with and without clustering?