Fix boundaries calculations (a bit hacky way)