refactoring for conciseness and optimization