Working on fixing nan bug