additional code improvement and bug fixes