Add debug messages and remove some unused functions.