closed some logic errors and added more input handling.