Fix IndexOutofboundException

In edge cases an index out of bound exception can occur when using the
channel up and channel down to navigate a gallery.