better extract logic