more tweaks to the code to try and get it working