Extract common functionality to helper function
Fix typo in comment