removed boundary in local memory: use if statements instead to handle boundary