- avoid numerous return statements
- final_log_data is overwritten numerous times, is that expected?
- create a nested function or something to handle the replicated "if failed..." statements