Refactoring

port i think