added tests; fixed bugs they revealed