Refactor and improve readability