Finally got it sort of working