Refactoring. Bug fixes.

Added comments to explain what's going on
Seperated out some logic that was becoming intermingled.
Fixed multiple bugs when watching a directory