refactored for better control over subroutine creation