fixed undefined val problem