JC: cleaned up the code.