finsish some bug adn simplify code