Several fixes

Fix fucked up 'return $$' due to a search/replace pattern done while
sleeping or thinking about something else ;).

Fix shooting your foot none local variables in function having same
name as global ones. Use none POSIX 'local' feature.