fix minor bugs
more error prevention
fix size checking error (file won't be created yet)