Add safety checks
Remove debug prints