Refatore the code structure