Added support for variable key count.
Fixed time math conflicts.