Added test and fixed errors