Fixing potential crashing bug