Re organized the codes