Good idea factoring this out into a new file - it was getting pretty long.