Cleaned up a little and added debugging code.