Fixed bugs, works with GUI program.