My attempt at solving #51