clean up logic, improve readability