Streamlined code with minor refactor