Refactoring to reduce duplication + some performance measurements