misc fixes

- safer string functions
- declaration/code separation