Stability fixes

Improved recognition of external function declarations, fixed ret
command to clean up stack after function.