code improvement, bugfixes