Added own threshold function