Updated master function