refactored all the codes.