Added resource release code (WARNING: crash)