added some code to check for functions. not completed.