Remove duplicated code and fix travis