logger added. error handling fixed.