re-adding code that was accidentally removed from trying to fix last 2
commits