massive refactor + partial log