Works now, todo change threshold func