Updated code to work better and keep going