some fixes to get this code to work