Fixed bug in read_nonempty; Added tests