Minor bug fix and code arrangement
Update side bar when changing  visibility