Updated code to work with modal view