Think this might work. Spent far too long on this