Fix code and test