Change searching on center to border, fix some bugs, add comments