Readding code from commit which was lost. lost commit: 1a9869d104e922d0a13753dd1ce926012b6c2f5f