changed var name counter to offset, todo