updated to latest working code