Make function readability improvements & tests