added code to handle user defined functions