Some refactoring to make it more concise