Bug fixes and safety checks