fixes the crash issue but the code is still wrong.