adds error handling in main "function"