added tests and changed api slightly