High gain ultraviolet photodetectors based on AlGaN/GaN heterostructures for optical switching