refactoring as suggested by haugstrup