Make function more portable