Adding latest WIP code
Various bug fixes