Change 1005 error level to warning
Fix bad loop condition
Prevent memory leak