Fixed boundaries calculations again. Few testings.