added conditions for undefined values