fix define checks
fix potential memory issue