Fixed bug in defined function