open/close rest loop (+ alot minor fixes)