cleared and reorganized some code