Fixes to function