Encapsulating common functionality in Function