Reafactored for ke2sql