Refactor by using n-tied architecture