Inlined a mapping func to shrink the code and improved comments.