Fixed code and test