unit tests + bug fixes