Refactored loop modeling module
Add custmization of loop modeling, and fix compatibility with python2.6