improved sidebar code