added tests, squashed bugs