fix some errors & refacto code