Lots of comments, some cleanup, many ifdefs