Adding tests. Minor improvements