improve sidebar algorithm