main.cpp bugs corrected