removed redundant code; added more logging.