just a few minor fixes.
added functions and global variables.