Minor fixes and code improvement