AMENDED AND RESTATED MASTER REPURCHASE AGREEMENT