refactoring. Crash fix. making the module more stable.