refactored all the codes