Fix bugs and warnings
Better file logging
Optimize logging and exceptions
Removed TODO after testing