Second version

More stable version. No out-of-range sub.