Fixing returning a value in void function