optimize and fix for regs functions