very rough pseudo-code of v1 functionality