added test and fixed bug