fixed null reference exception handling