Added threshold functions and hand detection