Moved populate document function