Added test and some errors fixed