completed (except some rearramgements and TODOs)