shadow bugfixing and minor refactoring