Added more error checks; Switched to readlines()