added logging throughout the code and exception handling