Bug fix with functions