fixed last function