Added truncation and modified sky_detect