reorganized and cleaned up