Reverts some changes to restore functionality and adds lots of comments.