Major refactoring for version 2.
Fixed logging and redirection.
Removed unused code.