refined the structure of int main and added basic exception handling