grabbed minimal necessary code from BamViews