added many if statments to look around the curent position

need to resolve the eror on line 69 70 and 75