Adding tests + bug fix