change 'and' to '&&' and make sorted method private