global refactor and final changes