resolved logic errors and loop.