clean code and add onDestroy function