Fixed some code. Minor errors. Major bug still exists, when using loop
mode.