refactored according to T. Kuhn.