Some engine fixes.

Fix initializing return buffer.
Fix possible array overrun.
Remove unneeded double-initialization of the vars.