refactor to make the code more succinct