reorginized code and deleted some code.