null check and bugfix