improvement to replicated code