Added implementation of Fun method, fixed some memory issues.