Added test and few minor fixes