Bugfixes and out-of-bound handling