improve logic and fix issues
fix possible crash issue