moved sidebar generation into a method