Fixed potential logical issues
Fix conflicts.