added tests and general improvements