Updated logic and added more configuration options