Adding tests and small fixes