tests + bug fixes