[#438] cleaned the function a bit