Refactor  and remove unnecessary codes.