Initial import from internal SVN.

Prefixed all functions and performed some small clean-up tasks
beforhand.