clean code and fix history bug