reorganize, partially commented