Fixed possible crash issue with deallocated delegate
Fixed codestyle