Adding tests; bug fix