Adding logs and slight refactoring