changed indentation to four spaces and added more error checking on input