Lots of fixes and rearranging, close to release state.