Adding tests fixing bugs