improvements in threshold function, and added a module for more analysis