Fixed issue with function