Code cleanup
Improved log + general refactoring