added tests and small fixes