added test and fix some bug