Made global variables static. Added comments.