Adding test and minor fixes