First solution to 3-4. Works, but is very verbose, and can probably be trimmed down a lot.