Solution for #1

My solution to #1 plus some bonus checks.