Added debug code, updated code for consistency