logging added and bug fix