Fixed a couple of bugs, added some configuration parameters