v2, with some cleaned up code