Fix bug caused by passing wrong arguments to function