refactor some code to kinmu.libs