Fixed bug with functions