added dead end checking