Refactoring + misc_tools