borrow code from sqerl