Resync with cfenllosa branch, incorporating new features