nice solution to 31 blatantly copied off the interwebs