Fixed logs and refactored