Fixed bug on boundaries