Recommit "Various refactoring + 1 bug fix"