Rewrote to split up configuration and logic