fixed out of range error and others. code now takes too long to run