Fix array overflow
Constrain background to map size