More code refactoring and some few improvements