Prepared for publish. Various small fixes and improvements