Ok, have split into 2 implementations for clarity.