better error management and logging implemented