added additional debug prints with checking if debug level enabled