added a whole lot more implementation and tests