#63: Fixed issues with log rotation, refactored code