split some code and fix some warning