reorganization; working function; have to clean up