Cleaned up and debugged.