working version, needs a fix for counters