more bugfixes and safety checks