Fixed several bugs in tick detection