Make function work as expected