restructured, with comments and TODO list