some minor modifications, plus some tests added