fix undefined check in functions