Solution by Robbie Hatley (github user "LoneWolfiNTj").