Fixed bug where the function didn't work correctly