Fix warning and code improvement