Add test and fix errors