Added more comments to explain core functions.