Updated with logging