FIX: possible NPE
FIX: must close input stream