First major commit, mostly code written in 2012, with bug fixes and changes recently.