Added EOF checking to address #199