Write unit tests. Minor updates