master function