- Added handling of empty file case.
- Minor refactoring.
- Code cleanup and minor commenting.