fixed freezes

fixed freezes on power failure, added preprocessor directives