Improve test and code