added functionality from commit 38f1b6f321526d4ab19058861e1f9569a67f8bce