Various bug fixes and changes to the example