Added error check to main