Moved a function in a more correct place
Simplified the main.m