Modified config, added checking for threshold value, refactored a bit