Global code improvement and bug fix
Merge branch