Refactor application architeture