Fix defined/length checks