optizate and fix bug