Fixed small errors in code arrangement in main