added Mode enum and restructured control flow for open
corrected bug where main called close instead of read