Refactoring preexec