Adding test and fix bug