More modular & added IF support