added more comments and fixed input error