Added logging and len helper function