Remove unnecesssary codes and refactor