various fix and code improvement