added exception handling and a main() function