Refactor endowments.js