added tests + bug fixes