introduced some more tuning parameters, code clean up and debugging