added a test and improvements