Final fix, think I've got it now