Cleaned up, commented version of Part 1