Move duplicated code for setting source positions into a common function