Added Master-Foreman relations. Fixed a memory leak.