Remove duplicated code and so unused code