refactor for clarity and functionality