Code Improvements

Some code improvements and commenting