Completed code answer. Whoops, wasn't committing that often...