refractoring, fix bugs