Common solution for both #48 and #46