Streamlined code with refactor