Clean up Sidebar code, move check for element existence into module.