updated main.cpp with proper IO