Minor Changes

Added basic comments
Fixed global variables
Removed duplicate function