Reduced unnecessary levels of scope in functions.

Added SAL notation.
Fixed function signatures