Fixed some issue with functions