Porting over the latst addiotion from the 6-dev version. Allow adjusting settings programatically etc.