Fixed rollover issue, made it faster with cloud function