added error logging to various functions in order to understand what's going on behind the scenes.