WIP: more comments, more conditions, more cleanup